Home Forums Plugin Support WP User Frontend Pro Custom Taxonomy (non hierarchical) e.g tags

This topic is: resolved

This topic contains 11 replies, has 5 voices, and was last updated by  cob-web 5 years, 7 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #3864

    kolhoffmmm
    Participant
    Post count: 10

    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.

    #3883

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #3906

    kolhoffmmm
    Participant
    Post count: 10

    Thanks Tareq I will try it out

    #3920

    kolhoffmmm
    Participant
    Post count: 10

    Thanks it is working great

    #4633

    sungkhum
    Participant
    Post count: 4

    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

    #6055

    seldomstatic
    Participant
    Post count: 2

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

    #6062

    Tareq Hasan
    Keymaster
    Post count: 2831

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

    #6071

    seldomstatic
    Participant
    Post count: 2

    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.

    #6073

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #6352

    cob-web
    Participant
    Post count: 14

    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! ๐Ÿ™‚

    #6354

    Tareq Hasan
    Keymaster
    Post count: 2831

    Auto completion doesn't yet work in the frontend. But the feature will come eventually in the future ๐Ÿ™‚

    #6355

    cob-web
    Participant
    Post count: 14

    Thanks Tareq for your super fast answer!

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Custom Taxonomy (non hierarchical) e.g tags’ is closed to new replies.