I’m working on a WordPress site with a large product database. I need to make a listing of all the products with a single taxonomy term exception. Using wp_query() creates a huge object and takes a long time. Also, for some reason, my arguments will not exclude products from the one taxonomy term I don’t want listed. Here is my current query:
$args = array( 'post_type' => 'products', 'post_status' => 'publish', 'orderby' => 'post_title', 'numberposts' => -1, 'tax_query' => array( 'taxonomy' => 'product-main-cats', 'field' => 'term_id', 'terms' => array(23), 'operator' => 'NOT IN', ), ); $prods = new WP_Query( $args );
I want to rewrite this query using the wpdb class so that I only fetch exactly what I need for my listing instead of the huge wp_query() object. The only columns I need from the wp_post table are, ID and post_title. I’m just not sure of the mySQL syntax, especially for excluding the posts related to the single taxonomy term. Can anyone help me rewrite this?
Read more here: Optimizing a WordPress Query