Home › Forums › Plugin Support › WP User Frontend Pro › Custom Taxonomy (non hierarchical) e.g tags
Tagged: custom, form field, taxonomy
This topic contains 11 replies, has 5 voices, and was last updated by cob-web 5 years, 6 months ago.
-
AuthorPosts
-
May 20, 2013 at 10:11 am #3864
The one thing i am really missing is a proper field for custom taxonomies which operate as tags (created as a non hierarchical taxonomy) Currently you can select the custom taxonomy (setup as tags not category) as a field, but the only problem is that it treats it like a category. you can't select a normal text box.
my custom taxonomy tags (let's call it business_tags) i would like to enter as tags (comma separated) I don't want to select them like categories as currently is the case.
I can use the default post_tags field, but I don't want to mix them
so there should be an extra option in that field type. currently it is dropdown,multiselect or checkbox. there should be an option textbox or something like that.
May 20, 2013 at 7:37 pm #3883Okay, I'm giving you the solution.
[php]
function wpufe_render_bus_tags( $form_id, $post_id, $form_settings ) {
$value = ”;if ( $post_id ) {
$post_tags = wp_get_post_terms( $post_id, ‘business_tags' );
$tagsarray = array();
foreach ($post_tags as $tag) {
$tagsarray[] = $tag->name;
}$value = implode( ‘, ‘, $tagsarray );
}
?>
<div class="wpuf-label">Business Tags</div>
<div class="wpuf-fields">
<input type="text" name="business_tags" value="<?php echo esc_attr( $value ); ?>" size="40">
</div>
<?php
}add_action( ‘wpufe_bus_tags', ‘wpufe_render_bus_tags', 10, 3 );
function wpufe_inesrt_business_tags( $post_id ) {
if ( isset( $_POST[‘business_tags'] ) ) {
$tags = explode( ‘,', $_POST[‘business_tags'] );
wp_set_post_terms( $post_id, $tags, ‘business_tags' );
}
}add_action( ‘wpuf_add_post_after_insert', ‘wpufe_inesrt_business_tags' );
add_action( ‘wpuf_edit_post_after_update', ‘wpufe_inesrt_business_tags' );
[/php]This code adds a input field named Business Tags. You've to create a action hook field and give the label
wpufe_bus_tags
and paste this code to your themesfunctions.php
. Now you'll see a input field just like tags and you can input yourbusiness_tags
taxonomy.May 21, 2013 at 4:58 am #3906Thanks Tareq I will try it out
May 21, 2013 at 11:15 am #3920Thanks it is working great
June 7, 2013 at 4:51 am #4633I also needed this feature and used the code you suggested. How would I make this action hook a required element in the form? I want to require the user to fill it out.
Thanks,
NathanJuly 17, 2013 at 9:32 am #6055This solution works great. How can I make the custom taxonomy form field required?
July 17, 2013 at 2:38 pm #6062The plugin now already supports non hierarchical taxonomy, so you don't need this modification.
July 17, 2013 at 7:36 pm #6071I'm using this action hook to allow users to add “custom” taxonomy tags such as genre, artist, year, etc. The hook works perfectly. I just want to know how I can make the form field a required value.
July 17, 2013 at 8:09 pm #6073If you change the Type to Text Input, users can input taxonomy.
Although, you can add attributes to your input
data-required="required"
andrequired="required"
to make it required. Alsodata-type="text"
for text input.July 26, 2013 at 11:02 pm #6352Hey Tareg,
it also works for me, BUT: when I fill in the custom taxonomy tags in the WP backend, I get suggestions of already existing tags. For example I'm using a custom taxonomy “filmmaker”. If I type the first letters “St”, it shows me the tags, that already exist e.g. “Steven Spielberg”. However this doesn't seem to be working in the front end form. Is there a way to make this work? That'd be fantastic! ๐July 26, 2013 at 11:18 pm #6354Auto completion doesn't yet work in the frontend. But the feature will come eventually in the future ๐
July 26, 2013 at 11:50 pm #6355Thanks Tareq for your super fast answer!
-
AuthorPosts
The topic ‘Custom Taxonomy (non hierarchical) e.g tags’ is closed to new replies.