List categories, subcategories and posts from custom taxonomy and custom post type

You just need to tweak the logic so that if ( have_posts() ) : is only run if get_term_children() is empty, which it will be on the lowest level: $term = get_queried_object(); $term_id = $term->term_id; $taxonomy_name = $term->taxonomy; $termchildren = get_term_children( $term_id, $taxonomy_name ); if ( ! empty( $termchildren ) ) { echo ‘<ul>’; foreach … Read more

Get all posts with empty meta_value

If I understand your question correctly, you want to query for region field only if $region variable is not empty? If so, this should work and it will be much prettier code than the one you suggested: $meta_query = array( array( ‘key’ => ‘state’, ‘value’ => ‘Alabama’, ), ); if ( $region ) { $meta_query[] … Read more

Custom query vars filters problem with pagination

The problem is the pagination parameter in the URL: <a href=”https://wordpress.stackexchange.com/questions/298648/<?php echo (in_array($marca_term->slug, $marca_arg)) ? esc_url(remove_query_arg(“marca’)) : esc_url(add_query_arg(‘marca’, “$marca_term->slug”)); ?>”> Here we see that the marca term is being added and removed, but the pagination parameter isn’t, but that’s a part of the URL not a parameter Instead, why not use the taxonomy archives and … Read more

Tax query is not working!

You are missing quotes around category as the taxonomy in your query: ‘taxonomy’ => category, Needs to be ‘taxonomy’ => ‘category’, So the taxonomy query looks this ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘terms’ => 14 ) ),

WP_Query meta value order is not working

If the variable you are storing in meta_value were an integer, you would not be able to store it as ’02’. So, apparently, your are storing a string. This indeed gives different orders depending on whether you store ’02’ or ‘2’, as is described under meta_value in the codex on WP_Query. So, as the codex … Read more