IF ( ! $loop->have_posts() ) condition doesn’t work – WP_Query

Products variations are a stored as a different post type, product_variation, so you have to add that post type to the query: ‘post_type’ => array( ‘product’, ‘product_variation’ ) Also, you could try to use WooCommerce specific functions, like wc_get_product_ids_on_sale(), wc_get_products() and so on, they could make your life easier when coding for WooCommerce.

What is the equivalent WP_Query of a SQL Query?

Because I don’t have the exact settings, I just make use of the variables showing in the questions to code. The code is tested with similar settings with meta value. If using WP_Query object, one more custom field is required to achieve the effect $queryArgs = [ ‘post_type’ => ‘author_cpt’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => … Read more

WooCommerce. How To Exclude Subcategory Products From Category Listing Page

If you don’t want a query to run on the admin you can call the conditional function is_admin() to check, if it returns true you can just return out of the function. Additionally, pre_get_posts is an action hook. function exclude_product_cat_children( $wp_query ) { if( is_admin() ) { return; } if( isset( $wp_query->query_vars[‘product_cat’] ) && $wp_query->is_main_query() … Read more

Access queried post ID in WP_Query

WordPress has quite a few global variables to choose from which may help. For example, you can use the global $post to get first post in the query. global $post; $my_meta_value = get_post_meta( $post->ID, ‘_another_meta_key’, true ); Or you could reach directly into the $wp_query object posts array and grab the first post: global $wp_query; … Read more

Slick slider for post doesn’t display anything

look at this example structure : /** * Section Servises */ $servises_info = new WP_query(‘pagename=правни-услуги’); if ($servises_info -> have_posts() ) : while ( $servises_info -> have_posts() ) : $servises_info -> the_post(); // look hire below $relayted_post = new WP_query(‘cat=2&order=ASC’); /* Start the Loop two */ while($relayted_post -> have_posts()): $relayted_post -> the_post(); $servises_data = get_the_content(); // … Read more