wp_get_object_terms() to get a list of all the terms attached to all the posts in the current query

I think you’re on the right track because wp_get_object_terms() can take an array of IDs for its first argument, it’s just that $wp_query is not the array you want. I can’t guarantee that this is more efficient (not my area of expertise), but I believe this [partially-tested] snippet would do what you want with at … Read more

Exclude specific slug in ‘get_terms’

The get_terms() (see docs) function accepts the same args as WP_Term_Query(see docs) You have to get those terms Ids first and then pass it to the exclude arg: // default to not exclude terms $ids_to_exclude = array(); $get_terms_to_exclude = get_terms( array( ‘fields’ => ‘ids’, ‘slug’ => array( ‘graduate’, ‘job-market-candidate’, ‘graduate-student’, ‘research’ ), ‘taxonomy’ => ‘role’, … Read more

Correct use of get_the_terms()

the_ID() print the post ID. You need to use the get_the_ID() which return the post ID. Example: foreach (get_the_terms(get_the_ID(), ‘taxonomy’) as $cat) { echo $cat->name; } Always remember the naming convention of WordPress for template tags. the which mean to print get which mean to return in most of the cases.

get a specific taxonomy term name

Use get_term() to get the name, slug, or description: $term = get_term( 1, ‘taxonomy_slug’ ); // Name echo $term->name; // Link echo get_term_link(1, ‘taxonomy_slug’); // OR echo get_term_link( $term );

wp_set_object_terms() is not replacing term, but creating a new one

In both the cases issue is not the other things, but the main value what you are sending to the second parameter, in your case $flightCategory: $flightCategory = array( 25 ); var_dump( $flightCategory ); wp_set_object_terms( $post_id, $flightCategory, ‘flight_categories’ ); But on the later version somehow, or literally you are actually passing something like below: $flightCategory … Read more

query multiple taxonomies

First of all, get all term slugs from the custom taxonomy space by current post ID. $space_terms = wp_get_post_terms( $post->ID, ‘space’ ); if( $space_terms ) { $space_terms = array(); foreach( $space_terms as $term ) { $space_terms[] = $term->slug; } } You should specify the logical relationship between each inner taxonomy array when there is more … Read more

How can I get category ID by category name?

The only alternative I know of (using core functions) is: // Get terms whose name begins with “my_name” get_terms( ‘category’, array( ‘name__like’ => ‘my_name’ ) ); // Get terms whose name contains “my_name” get_terms( ‘category’, array( ‘search’ => ‘my_name’ ) ); If you need an exact match, you’ll have to execute a custom query. $wpdb->get_results( … Read more