Add Taxonomy Description with wp_set_post_terms

You can’t use wp_set_post_terms() to set the term description, but you can use wp_insert_term() to create the term and set the description (plus other details), and then pass the term ID to wp_set_post_terms(). Working example for one term: $taxonomy = ‘category’; $term_name=”Foo Bar”; // First we create the term (if it doesn’t already exist). if … Read more

Leveled – Terms foreach

Why not use wp_list_categories( ‘taxonomy=section’ ) ? It’ll do all the nesting & hard work for you! If you want more control over the HTML output, implement a custom walker.

wp_set_object_terms not working inside loop

You can pass an array of terms to wp_set_object_terms, there is no need for the for each: $genres= array(‘action’, ‘comedy’, ‘horror’); $ret = wp_set_object_terms( $postId, $genres, ‘genres’);

wp_set_post_terms is assigning only the last of several terms to a post

You need send a fourth argument to the function: wp_set_post_terms($post_id, $actor_term_id, ‘actor’, true); Each time the function executes, you’re replacing any existing terms. The fourth argument specifies that you wish to append them. https://codex.wordpress.org/Function_Reference/wp_set_post_terms

How to get a post’s associated taxonomies and terms in wp api v2

Ok, I just stumbled upon the answer buried deep in the github issues page: https://github.com/WP-API/WP-API/issues/1403 The answer is: the reason is that the terms / meta etc are different objects, and in typical REST design going a GET on a single resource, will give you that resource, not that resource and a bunch of other … Read more

Conditional Statement with Multiple Terms?

Firstly, create some sort of association between the icon class and the term name: $icons = array( ‘webinar’ => ‘fa-desktop’, ‘report’ => ‘fa-file-text-o’, ‘video’ => ‘fa-youtube-play’, ‘past-project’ => ‘fa-cogs’, ‘meeting-material’ => ‘fa-users’, ‘info-sheet’ => ‘fa-info-circle’, ); Then loop through each term assigned to the post and output the corresponding icon: $terms = get_the_terms( get_the_ID(), ‘type’ … Read more

Why does wp_get_object_terms add a period after terms are output?

wp_get_object_terms() isn’t the problem. the_taxonomies() is doing the outputting; it doesn’t return anything. So, your code is equivalent to: the_taxonomies( ‘before=<ul><li>&sep=</li><li>&after=</li></ul>’ ); wp_get_object_terms( $id, null ); Now, if you go to wp-includes/taxonomy.php you will find the dot in the_taxonomies() source. To remove the dot, you need to add a filter: function remove_the_dot($template) { return ‘%s: … Read more

Query to get term id using post id?

It is not good practice to use query when you have already builtin functions but for your need. Try this solution: global $wpdb; $meta = $wpdb->get_row( “SELECT * FROM `wp_postmeta` WHERE `meta_id` = $id” ); //will return same object like returned by get_metadata_by_mid() function print_r($meta); Debugging Technique: As you mentioned, get_metadata_by_mid() isn’t working on live … Read more

get_terms – name__like a number

Looking at the get_terms function definition, the value for name__like will be passed to the SQL query like: ” AND t.name LIKE ‘{$name__like}%'” As such, I believe that you can only search for one of the numbers. As an alternative strategy, you could iterate over the numbers you want to pull from the database: $terms … Read more

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