How to add tax_query to $args with concatenation

Try this… <?php if ( $value[ ‘priceRange’ ] == 0 && $value[ ‘tags’ ] == 0 && !$value[ ‘type’ ] ) { if ( !$value[ ‘priceRange’ ] ) { $value[ ‘priceRange’ ] = array( 0, 1000000 ); } $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, ); } if ( $value[ ‘priceRange’ ] == … Read more

How do I get Woocommerce product variation name and variation description in a WP_Query?

OK, so soon after posting I came up with a working solution. With this code I get the price straight from the variation price field, not from the description field as I mentioned in my question. <?php $params = array(‘posts_per_page’ => -1, ‘post_type’ => ‘product_variation’, ‘order’ => ‘ASC’); $wc_query = new WP_Query($params); global $product; ?> … Read more

Multiple wordpress queries with nested output (odd – even)

Why not just do straight what you’ve wanted. <?php $args_one = array( ‘cat’ => 7, ‘posts_per_page’ => 8, ); $args_two = array( ‘cat’ => 10, ‘posts_per_page’ => 8, ); // will run 2 sql queries. $posts_one = get_posts( $args_one ); $posts_two = get_posts( $args_two ); $all_posts = array(); // lets merge them into 1 array. … Read more

wp_trim_words strips dashicons

Your problem is that your filter is trimming all titles to 7 “words”. This includes blog posts, pages, menu item labels, revision names, and even product names, if you have products. You need to adjust your filter to be less aggressive and only target the titles that you need to truncate. For example, the following … Read more

Limit number of posts in loop

I consider the right way could be filtering of total number of found posts like this. function my_custom_found_posts_limiter( $found_posts, $wp_query ) { $maximum_of_post_items = 100; // place your desired value here or read if from option\setting. if ( ! is_admin() && $wp_query->is_main_query() && $wp_query->is_post_type_archive( ‘blog_posts’ ) ) { if ( $found_posts > $maximum_of_post_items ) { … Read more

WP Job Manager plugin – Listing only the twelve job categories on frontpage order by jobs they have

Edited: This is a much simpler version of what you are looking to do. You don’t need WP_Query(). You can use a foreach loop and an iterator: <?php echo ‘<ul class=”job-category-list”>’; // Get the terms and order them by count in descending order. $terms = get_terms( [ ‘taxonomy’ => ‘job_listing_category’, ‘orderby’ => ‘count’, ‘order’ => … Read more

exclude product with available tag

You can setup a tax_query with the NOT IN operator. WP_Query( array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 500, ‘tax_query’ => array( ‘relation’ => ‘AND’ array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array( ‘cars’ ), ), array( ‘taxonomy’ => ‘product_tag’, ‘field’ => ‘slug’, ‘terms’ => array( ‘whatever_tag_i_dont_need’ ), ‘operator’ => ‘NOT IN’, ), ), … Read more

wp_query is showing posts from other categories

I have used Custom Select Query to gather all information in a single call and hope it may work out. global $wpdb; $selected_cat_id = ‘6,7,8,9’; $post_count = 5; $custom_query = “SELECT $wpdb->posts.ID, $wpdb->posts.post_title, $wpdb->terms.name FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->terms ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->terms.term_id) WHERE 1=1 AND ($wpdb->term_relationships.term_taxonomy_id IN … Read more

Order by meta_key doesn’t work

Current Query $args = array( ‘post_type’ => ‘brands’, ‘meta_query’ => array( array( ‘key’ => ‘br_type’, ‘value’ => ‘Aviation’ ), array( ‘key’ => ‘br_category’ ), array( ‘key’ => ‘br_name’ ) ), ‘posts_per_page’ => -1, ‘orderby’ => [ ‘br_category’ => ‘ASC’, ‘br_name’ => ‘ASC’ ], ‘order’ => ‘ASC’, ‘fields’ => ‘ids’ ); produce this SQL query ‘SELECT … Read more