CTP – check for value inside objects

There’s no need for two loops. Just iterate over the terms and use in_array(): foreach ( $terms as $term ) { if ( in_array( $term->slug, $months ) { echo ‘yes’; else echo ‘no’; } }

Custom term templates

If you look at the template hierarchy, you need to create a template taxonomy-{$taxonomy}-{$term}.php. In your case, that template will be called taxonomy-product_cat-awesome.php where I assumed the slug of your term is awesome Just a tip, the “categories” of a custom taxonomy is called terms. The build in taxonomy category “categories” is also called terms, … Read more

How to extract one field from wp_get_post_terms objects?

$terms is an array of objects. You must select one of the array entries before you can reference its properties (fields). This will print the ‘name’ of the first object (index zero): if ($terms) { echo $terms[0]->name; } This will print all the ‘name’ fields: if ($terms) { foreach( $terms as $term ) echo $term->name; … Read more

How to get term by name with parent id?

Use get_terms and specify name and parent. $name=”Flowers”; $parent_id = 42; $args = array( ‘name’ => $name, ‘parent’ => $parent_id ); $terms = get_terms( ‘category’, $args );

Temporarily un-associate term for an amount of time

I think since the users are a CPT, it would be well suited to do this in post_meta on the user. You could store the temporarily unsubscribed term there and check against when sending notifications. For example, your post_meta could be an array such as this: subscribed_list_term => “maybe_cool_for_summer_list_term”, subscription_duration => “halted_during_all_seasons_but_summer” Obviously that is … Read more

Get get_terms alphabetically

Maybe try tu use name__like as MySQL LIKE : $args = array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘name__like’ => ‘b%’, ‘number’ => ’20’, );

Getting terms to have space between them

You can either concatenate your call to echo with a space or newline. Space: <?php $terms = get_the_terms($property[‘ID’], ‘property_sub_type’); if(!empty($terms)){ foreach($terms as $value){ echo $value->name . ” “; } } ?> Newline: <?php $terms = get_the_terms($property[‘ID’], ‘property_sub_type’); if(!empty($terms)){ foreach($terms as $value){ echo $value->name . “\n”; } } ?>

Display posts belonging to child term

I was able to get this working with the following code. I used the relation operator AND, referenced the var ($this_term) that contained get_queried_object(); to set the taxonomy in the tax_query and adjusted the term field in the tax_query. $this_term = get_queried_object(); $args = array( ‘parent’ => $this_term->term_id, ‘orderby’ => ‘slug’, ‘hide_empty’ => false ); … Read more

Echo term slug op post on archive page

The get_the_terms function returns array of WP_Term objects. So you need to use something like this to echo a single term slug: echo $terms[0]->slug; Also be aware of results of this function. As documentation says it returns: Array of WP_Term objects on success, false if there are no terms or the post does not exist, … Read more

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