WordPress.org

Forums

[resolved] wp_set_post_terms, example needed (3 posts)

  1. mediabros
    Member
    Posted 3 years ago #

    here is the thing, i think i do not understand the function correctly wp_set_post_terms() so i need a helping hand here.

    i have a custom post type "products", with custom taxonomy "product-category".

    i have te following:

    add_post_meta($post_id, 'product_color', 'red', 1);
    
    $terms = array( 'cars', 'boats', 'bicycle' );
    
    wp_set_post_terms( $post_id, $terms, 'product-category');

    the post meta is correctly added, so what am i doing wrong with the wp_set_post_terms function?

  2. jnhghy
    Member
    Posted 3 years ago #

    Hi mediabros,
    you need to try some different approche, passing the taxonomy name is not the best way to do it, it should work but if it dosen't. You need to try to achive this by passing the taxonomy id and you may also try to pass the taxonomy by reference:
    wp_set_post_terms( $post_id, $term, &$taxonomy );
    I'll post the codex link also it might help somebody :)
    http://codex.wordpress.org/Function_Reference/wp_set_post_terms
    Regards!

  3. mediabros
    Member
    Posted 3 years ago #

    thanks, i used get_term to retrieve the ids and replaced those with the names in the $terms array in the example above.

    http://codex.wordpress.org/Function_Reference/get_term

Topic Closed

This topic has been closed to new replies.

About this Topic