tax_query shows no results if nothing is selected

So far good, add taxonomy condition by checking the suburbs and states Value. // Suburbs if( !empty( $_GET[‘suburbs’] ) ) { $suburbs = $_GET[‘suburbs’]; } // States if( !empty( $_GET[‘states’] ) ) { $states = $_GET[‘states’]; } // Query arguments. $args = array( ‘post_type’ => ‘properties’, ‘posts_per_page’ => 10, ); $taxquery = array(); // if … Read more

WP_Query use for a filter with multiple Taxonomies and Terms

Try this way: $args = array( ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_status’ => ‘publish’ ); if ( isset( $_POST[‘typefilter’] ) && $_POST[‘typefilter’] !== ” ) { $args[‘post_type’] = ‘post_type_x’; $args[‘tax_query’][0][‘taxonomy’] = ‘type_emp’; $args[‘tax_query’][0][‘field’] = ‘id’; $args[‘tax_query’][0][‘terms’] = $_POST[‘typefilter’]; $args[‘tax_query’][0][‘operator’] = ‘IN’; } if ( $_POST[‘typefilter’] == ”) { $args[‘post_type’] = ‘post_type_x’; } // If … Read more

How to Get All Taxonomies AND All Terms For Each Taxonomy With Post Count Zero

You can do this with just get_terms – this allows you to fetch all (or some) of the terms from one (or more) taxonomies. By default it excludes ’empty’ terms, so you’ll need to set the arguments appropriately. //Array of taxonomies to get terms for $taxonomies = array(‘category’,’post_tags’,’my-tax’); //Set arguments – don’t ‘hide’ empty terms. … Read more

How to reduce the database query-es

You can try this version with WP_Query() called only once: <?php $args=array( ‘post_type’ => ‘stiri’, ‘posts_per_page’ => 5, ‘taxonomy’ => ‘stire’, ‘stire’ => ‘articole-speciale’ ); $recentPosts = new WP_Query($args); ?> <div id=”featured” > <ul class=”ui-tabs-nav”> <?php $i=0; while ($recentPosts->have_posts()) : $recentPosts->the_post(); $i++;?> <li class=”ui-tabs-nav-item ui-tabs-selected” id=”nav-fragment-<?php echo $i;?>”> <a href=”#fragment-<?php echo $i;?>”><img src=”/scripts/timthumb.php?src=<?php the_field(‘imagine_stire’); ?>&amp;h=50&amp;w=80&amp;zc=1″ … Read more

SQL Statement generated by WP_Query not producing expected results

It looks like this section: AND (wptom_posts.post_status=”publish” OR wptom_posts.post_author = 1 AND wptom_posts.post_status=”private”) is not tied in at all to the two different query conditions… Perhaps the original code should be three conditions for part 1: array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘operator’ => ‘IN’), array( ‘taxonomy’ => ‘post_tag’, ‘field’ … Read more

Custom SQL Query on Custom Post Type. Order by Taxonomy?

Just looking at the term_taxonomy table, you are selecting everything correctly, but the last part: WHERE $wpdb->posts.post_type=”publications” AND $wpdb->terms.slug = %s AND $wpdb->term_taxonomy.taxonomy = ‘category’ ORDER BY $wpdb->term_taxonomy.taxonomy = ‘topics’ DESC from the post_type of publications, the terms slug of %s, and has the taxonomy of categories, but you are never selecting the taxonomy topics. … Read more

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