If product is in sub-category show code

You can probably just make use of has_term( $term, $taxonomy, $post ) which will check if the specific post belongs to the term given You can do something like this (Edit: Add post ID if this is used in a function) global $post; if(has_term( ‘lucha’, ‘product_cat’, $post->ID )) { //do something if post has lucha term }else{ //do something … Read more

Accessing Post ID Within Loop

The problem probably comes from whenever a $post has no terms set. You need to set $brand = array() outside your IF statement, add it just under get_the_terms(). At that point it also wouldn’t hurt to wrap your switch statement in a if( ! empty( $brand ) ) { Another problem I see with this … Read more

Get current post’s nav menu name (term name)

You are missing a link. The posts are not assigned to the menus directly. There is a post type nav_menu_item in nav_menu taxonomy which links posts (or other kinds of destinations) to their place in menu. This snippet should get you started on retrieval: $menu_items = get_posts( [ ‘post_type’ => ‘nav_menu_item’, ‘meta_query’ => [ [ … Read more

How to query if meta_key does exist or not?

Adding a NOT EXISTS clause should force LEFT JOINs: ‘meta_query’ => array( ‘relation’ => ‘OR’, array(‘key’ => ‘file_gallery’, ‘value’ => ‘1’, ‘compare’ => ‘!=’), array(‘key’ => ‘file_gallery’, ‘compare’ => ‘NOT EXISTS’), ),

How can I get 3 different taxonomy type terms in a div class element?

If using get_the_terms, you can just do your if loop once for each taxonomy and then join them after the three loops. Of course, it would probably be more efficient to use: wp_get_post_terms( $post_id, $taxonomy, $args ); You could then do something like: wp_get_post_terms( $post_id, array( ‘resource_roles’, ‘resource_media’, ‘resource_theme’ ) ); Which would pull all … Read more

Double slash in the_terms URL

First Assumption: That an extra slash was being added for some reason To see what was going on, I wanted to see what was going on in the array. When I print_r() the array I get the following: Array ( [10] => stdClass Object ( [term_id] => 10 [name] => Mozilla [slug] => mozilla [term_group] … Read more

More efficient way to list posts by category [duplicate]

My suggestion would be to pass different arguments to Wp_Query Class. using ‘cat’ property, passing category Ids. <?php $custom_query = new WP_Query( array( ‘cat’ => ‘1,2,3,4’ ‘post_type’ => ‘my_post_type’, ‘posts_per_page’ => -1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ) ); ?> OR using ‘category_name’ property passing category slug’s as string parameters. <?php $custom_query = new … Read more