Wp set post terms not work

As stated in the wp_set_post_terms Comment: This function will only work on the native post type. For a taxonomy on a custom post type use wp_set_object_terms() wp_set_object_terms

get_terms() but with additional dimensions?

I think I have cracked this, thanks to a Redditor’s help. The advice was, effectively: start with 3 and 4 (“Use get_posts() to build an array of post ids that match conditions 3 and 4”) then refine by 1 and 2 (“then drop that array into the object_ids argument for your get_terms() query”)… Like… // … Read more

has_term() does not return when term is assigned post?

I suspect that the Codex information for has_term() is incorrect: <?php has_term( $term, $taxonomy, $post ) ?> And for the $taxonomy parameter: $taxonomy (string) (optional) Taxonomy name Default: ” But if you look at the source for has_term(): $r = is_object_in_term( $post->ID, $taxonomy, $term ); So, $taxonomy is passed to is_object_in_term(): <?php is_object_in_term( $object_id, $taxonomy, … Read more

wp_update_term not creating new unique slug

I think you are running into trouble with these lines in wp_update_term(): 3287 // Merge old and new args with new args overwriting old ones. 3288 $args = array_merge($term, $args); https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/taxonomy.php#L3287 The array passed in gets merged with the data already in the DB. Set your slug explicitly: $nname=”my new name”; wp_update_term( 10, ‘artists’, array( … Read more

get_post_terms not working as expected

I misunderstood what you were trying to do before. I thought you wanted to list the terms associated with one particular post – the one you are on. Whoops! Try this instead: $terms = get_terms(‘fruit_category’); if(!empty($terms)){ echo “<ul>”; foreach ( $terms as $term ) { echo ‘<li><a href=”‘.get_term_link($term->slug, ‘fruit_categories’).'”>’. $term->name . “</a></li>”; } echo “</ul>”; … Read more

Term begins with a letter

You will need to filter the query, which you can do with the terms_clauses hook. This is very similar to G-M’s solution but does not require a prefix on your search string. function old_style_name_like_wpse_123298($clauses) { remove_filter(‘term_clauses’,’old_style_name_like_wpse_123298′); $pattern = ‘|(name LIKE )\’%(.+%)\’|’; $clauses[‘where’] = preg_replace($pattern,’$1 \’$2\”,$clauses[‘where’]); return $clauses; } add_filter(‘terms_clauses’,’old_style_name_like_wpse_123298′); // $letter=”str”; // test $terms = … Read more

How to order get_term_children output by alphabetic order

Per your comment (and hopefully an edit to the question) : I did it like so: foreach ( $termchildren as $child ) { $term = get_term_by( ‘id’, $child, $taxonomy_name, array( ‘orderby’ => ‘name’, ‘hide_empty’ => 0) ); Formatted: foreach ( $termchildren as $child ) { $term = get_term_by( ‘id’, $child, $taxonomy_name, array( ‘orderby’ => ‘name’, … Read more

Prevent Selected Terms Rising to the Top

This bugs me too. It is very confusing, so I thought I’d look into it. That meta box is created in “wp-admin/includes/meta-boxes.php” on line ~399. It uses wp_terms_checklist. The problem codes seems to be this (it is one in source): <?php wp_terms_checklist( $post->ID, array( ‘taxonomy’ => $taxonomy, ‘popular_cats’ => $popular_ids ) ) ?> That leaves … Read more

How do I access a single term from a post?

It’s a little bit hard to be sure, what are you asking exactly, but… Let me try to answer… So somewhere in single.php you’re getting terms for current post using this code: $terms = wp_get_post_terms($post->ID, ‘mytax’, array(“fields” => “all”)); and you want to get the ID of first term from that list? If so, you … Read more