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’; } }
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’; } }
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
$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
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 );
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
Maybe try tu use name__like as MySQL LIKE : $args = array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘name__like’ => ‘b%’, ‘number’ => ’20’, );
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”; } } ?>
You can use get_terms() to get an array of child slugs: /** * Get child term slugs from given term parent * * @param Integer $parent_id ( Parent Term ID ) * @param String $taxonomy ( Taxonomy Slug ) * * @return Array( $term_id => $child_slug ) */ function get_child_slugs( $parent_id = 0, $taxonomy = … Read more
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
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