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

Custom archive page based on array of categories and tags

This turned out to be a quite extensive little project for me. BASIC IDEA My approach was to go with a custom archive page as this seems to be the best approach here. The thing with custom taxonomies is that if you have a structure in place, changing that would become a real messy expedition. … 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

WP_query taxonomy + get all posts with two terms from same taxonomy

You don’t need to 2 array for tax query. You can try this scenario: $args2 = array(‘post_type’ => ‘custom’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘events’, ‘field’ => ‘slug’, ‘terms’ => array( ‘tag1’, ‘tag-2’) ) ) ); $query = new WP_Query($args); echo $query->post_count; You can see the Codex for better understanding.

WP 5.8 “Query Loop” block: where to place custom query?

Looking into render_block_core_post_template() we can see it calls build_query_vars_from_query_block() (previously named construct_wp_query_args) to setup the query arguments of WP_Query from the Query` block properties. From there I don’t see it supporting custom taxonomies for the secondary query … yet! Work-around-idea: For the Query Loop: add a search keyword for using custom taxonomies, e.g. :query-motor-electric: and … Read more

Exclude from search all custom posts which are NOT in a taxonomy term

After reading your revised question it was easier to comprehend what you are trying to do. My new solution looks like the thing you wanted to do in the first place: it just excludes all posts which are of your custom type but don’t have the “yes”-term associated with it: $custom_query = array(); $custom_query[‘post_type’] = … Read more

SQL QUERY needed to get POST category (taxonomy) ? – MUST be SQL statement

You can try this SQL query for the taxonomy ‘mi_neighborhoods‘ and let’s take POST_ID = 1304 SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON (tt.term_id = t.term_id) INNER JOIN wp_term_relationships AS tr ON (tr.term_taxonomy_id = tt.term_taxonomy_id) WHERE tt.taxonomy IN (‘mi_neighborhoods’) AND tr.object_id IN (1304) ORDER BY t.name ASC; In general … Read more

wp_get_object_terms() to get a list of all the terms attached to all the posts in the current query

I think you’re on the right track because wp_get_object_terms() can take an array of IDs for its first argument, it’s just that $wp_query is not the array you want. I can’t guarantee that this is more efficient (not my area of expertise), but I believe this [partially-tested] snippet would do what you want with at … Read more