Get post terms for multiple posts at once?

That would be wp_get_object_terms. You’d need an array of post id’s as the input, together with the taxonomy you want to retrieve the terms for (let’s say: books). This should work (untested): $my_query = new wp_query ($args); $my_posts = $my_query->posts; $my_post_ids = wp_list_pluck ($my_posts, ‘ID’); $my_terms = wp_get_object_terms ($my_post_ids, ‘books’);

How to Get All Taxonomies AND All Terms For Each Taxonomy With Post Count Zero

You can do this with just get_terms – this allows you to fetch all (or some) of the terms from one (or more) taxonomies. By default it excludes ’empty’ terms, so you’ll need to set the arguments appropriately. //Array of taxonomies to get terms for $taxonomies = array(‘category’,’post_tags’,’my-tax’); //Set arguments – don’t ‘hide’ empty terms. … Read more

how is it possible that using wp_insert_category throw a fatal error?

The init action is the wrong place. This is because init runs on all requests, admin or front-end, but the wp_insert_category function is an admin-side only function. You generally don’t insert categories from the front end. Move to a more specific action, one that will be run in the admin side. Probably from your plugin’s … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)