Home Forums Plugin Support WP User Frontend Pro Category not being assigned properly

This topic is: resolved

This topic contains 8 replies, has 3 voices, and was last updated by  Alex 6 years ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #4095

    ForestNation
    Participant
    Post count: 27

    Hi,
    Frontend form for custom post type allowing users to select custom post type categories.

    Drop down list shows the categories correctly for that post type.

    However, the selected category does not save properly and a new one seems to be created with just a number. e.g. I selected category syncrude and 39 was created and saved with the post.

    Can you help please…

    #4099

    Alex
    Participant
    Post count: 27

    Hi ForestNation,

    I am having the exact same issue with a custom taxonomy on a custom post type. I can include the custom taxonomy successfully on the form, but then when it save it converts all terms to a #number.

    #4105

    Tareq Hasan
    Keymaster
    Post count: 2831

    The problem happens when the taxonomy is not hierarchical, so making it hierarchical will solve the problem.

    #4146

    ForestNation
    Participant
    Post count: 27

    Thanks Tareq, this worked.

    #4150

    Alex
    Participant
    Post count: 27

    I want my custom taxonomy to act like tags, though, not hierarchical…

    #4170

    Tareq Hasan
    Keymaster
    Post count: 2831

    Take a look here.

    #4175

    Alex
    Participant
    Post count: 27

    Thanks for the reply, Tareq.

    That is similar to what I'm looking for but not exactly the same. I want to have a non-hierarchical custom taxonomy and have them in checkboxes on the form, not text inputs. That way the customer has to check off which custom taxonomy terms apply.

    I can add this to the form, no problem. But the problem arises when the terms are saved and get converted into numbers.

    For now I have changed the custom taxonomy to be hierarchical as a way around this, but not sure if that will cause problems down the line.

    #4185

    Tareq Hasan
    Keymaster
    Post count: 2831

    So open up /class/frontend-form.php line 270, you'll see this code wp_set_post_terms( $post_id, $_POST[$taxonomy['name']], $taxonomy['name'] );, replace this with the code below and should be working:
    [php]
    if ( is_taxonomy_hierarchical( $taxonomy[‘name'] ) ) {
    wp_set_post_terms( $post_id, $_POST[$taxonomy[‘name']], $taxonomy[‘name'] );
    } else {
    if ( $tax ) {
    $non_hierarchical = array();

    foreach ($tax as $value) {
    $term = get_term_by( ‘id', $value, $taxonomy[‘name'] );
    if ( $term && !is_wp_error( $term ) ) {
    $non_hierarchical[] = $term->name;
    }
    }

    wp_set_post_terms( $post_id, $non_hierarchical, $taxonomy[‘name'] );
    }
    } // hierarchical
    [/php]

    #4206

    Alex
    Participant
    Post count: 27

    that seems to be working! thank you very much Tareq. we could mark this as resolved.

    (for anyone else, the filename in question is /class/frontend-form-post.php…)

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

The topic ‘Category not being assigned properly’ is closed to new replies.