Up to 50 percent off

Custom Taxonomy (non hierarchical) e.g tags

This topic contains 11 reply and 5 voices, and was last updated by cob-web 11 years, 3 months ago
Viewing 11 Posts - 1 through 11 (of 11 total)
Author Posts
May 20, 2013 at 10:11 am 3864
cob-web 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 3883
Tareq Hasan Tareq Hasan

Okay, 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 themes functions.php. Now you’ll see a input field just like tags and you can input your business_tags taxonomy.

May 21, 2013 at 4:58 am 3906
kolhoffmmm kolhoffmmm

Thanks Tareq I will try it out

May 21, 2013 at 11:15 am 3920
kolhoffmmm kolhoffmmm

Thanks it is working great

June 7, 2013 at 4:51 am 4633
sungkhum sungkhum

I 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,
Nathan

July 17, 2013 at 9:32 am 6055
seldomstatic seldomstatic

This solution works great. How can I make the custom taxonomy form field required?

July 17, 2013 at 2:38 pm 6062
Tareq Hasan Tareq Hasan

The plugin now already supports non hierarchical taxonomy, so you don’t need this modification.

July 17, 2013 at 7:36 pm 6071
seldomstatic seldomstatic

I’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 6073
Tareq Hasan Tareq Hasan

If you change the Type to Text Input, users can input taxonomy.

Although, you can add attributes to your input data-required="required" and required="required" to make it required. Also data-type="text" for text input.

July 26, 2013 at 11:02 pm 6352
cob-web cob-web

Hey 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 6354
Tareq Hasan Tareq Hasan

Auto completion doesn’t yet work in the frontend. But the feature will come eventually in the future 🙂

July 26, 2013 at 11:50 pm 6355
cob-web cob-web

Thanks Tareq for your super fast answer!

Viewing 11 Posts - 1 through 11 (of 11 total)