{"id":7404,"date":"2023-12-04T22:09:35","date_gmt":"2023-12-04T22:09:35","guid":{"rendered":"https:\/\/www.kadencewp.com\/help-center\/?post_type=docs&#038;p=7404"},"modified":"2026-04-22T16:32:11","modified_gmt":"2026-04-22T16:32:11","password":"","slug":"custom-queries-advanced-query-loop","status":"publish","type":"docs","link":"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/custom-queries-advanced-query-loop\/","title":{"rendered":"Custom Queries for the Advanced Query Loop Block (Filter)"},"content":{"rendered":"\n<p>The <a href=\"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/advanced-query-loop-block\/\">Advanced Query Loop<\/a> block (<a href=\"https:\/\/www.kadencewp.com\/kadence-blocks\/pro\/\">Kadence Blocks Pro<\/a>) provides settings to create a custom query loop. However, sometimes, you need to alter the query beyond the capabilities of the Advanced Query Loop&#8217;s settings. In these cases, you can add a code snippet to alter the <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/\" data-type=\"link\" data-id=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/\" target=\"_blank\" rel=\"noopener\">WordPress Query<\/a> object. You can add PHP code to your site using a plugin like <a href=\"https:\/\/www.kadencewp.com\/kadence-theme\/knowledge-base\/advanced\/how-to-add-a-custom-filter-or-function-with-code-snippets\/\">Code Snippets<\/a> or your functions.php file (in a <a href=\"https:\/\/www.kadencewp.com\/kadence-theme\/knowledge-base\/advanced\/what-is-a-child-theme-should-i-install-one-if-so-how\/\">child theme<\/a>).<\/p>\n\n\n\n<p>If you want to modify the query arguments, you can make use of the &#8216;<strong>kadence_blocks_pro_query_loop_query_vars<\/strong>&#8216; filter. Here is an example that implements the filter.<\/p>\n\n\n<style>.kb-table-of-content-nav.kb-table-of-content-id7404_7f86fa-c2 .kb-table-of-content-wrap{padding-top:var(--global-kb-spacing-sm, 1.5rem);padding-right:var(--global-kb-spacing-sm, 1.5rem);padding-bottom:var(--global-kb-spacing-sm, 1.5rem);padding-left:var(--global-kb-spacing-sm, 1.5rem);}.kb-table-of-content-nav.kb-table-of-content-id7404_7f86fa-c2 .kb-table-of-contents-title-wrap{padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id7404_7f86fa-c2 .kb-table-of-contents-title{font-weight:regular;font-style:normal;}.kb-table-of-content-nav.kb-table-of-content-id7404_7f86fa-c2 .kb-table-of-content-wrap .kb-table-of-content-list{font-weight:regular;font-style:normal;margin-top:var(--global-kb-spacing-sm, 1.5rem);margin-right:0px;margin-bottom:0px;margin-left:0px;}<\/style>\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_aa5514-cc, .wp-block-kadence-advancedheading.kt-adv-heading7404_aa5514-cc[data-kb-block=\"kb-adv-heading7404_aa5514-cc\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_aa5514-cc mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_aa5514-cc[data-kb-block=\"kb-adv-heading7404_aa5514-cc\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_aa5514-cc img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_aa5514-cc[data-kb-block=\"kb-adv-heading7404_aa5514-cc\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h2 id=\"examples\" class=\"kt-adv-heading7404_aa5514-cc wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_aa5514-cc\">Examples<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\n   if ( $ql_id == 5283 ) {\n      $query['tax_query'] = array(\n         array(\n            'taxonomy' =&gt; 'category',\n            'field' =&gt; 'slug',\n            'terms' =&gt; 'sub',\n         )\n      );\n   }\n   \n   return $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n\n<p>In the above code, the <strong>$ql_id<\/strong> is set to <strong>5283<\/strong>. This is the post ID of the specific query you want to target. If you don&#8217;t provide the conditional &#8220;if&#8221; statement to target a query ID, all of your queries will share the arguments, which isn&#8217;t ideal. Among other ways, you can find the <strong>$ql_id <\/strong>by navigating to <strong>Kadence Blocks &gt; All Queries<\/strong>, hovering over the edit link of your desired query, and looking at the bottom left corner of your browser window. Be sure to change the ID to suit your needs.<\/p>\n\n\n<style>.kb-image7404_b7d405-7b .kb-image-has-overlay:after{opacity:0.3;}<\/style>\n<div class=\"wp-block-kadence-image kb-image7404_b7d405-7b\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"924\" src=\"https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2023\/12\/Query-Post-ID.jpeg\" alt=\"Query Post ID\" class=\"kb-img wp-image-7406\" srcset=\"https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2023\/12\/Query-Post-ID.jpeg 463w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2023\/12\/Query-Post-ID-150x300.jpeg 150w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2023\/12\/Query-Post-ID-257x512.jpeg 257w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><\/figure><\/div>\n\n\n\n<p>The example also uses the <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#taxonomy-parameters\" data-type=\"link\" data-id=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#taxonomy-parameters\" target=\"_blank\" rel=\"noopener\">Simple Taxonomy Query<\/a> provided by the WordPress Query documentation. Here are some additional examples that have been modified from the WordPress documentation.<\/p>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_af72dc-e7, .wp-block-kadence-advancedheading.kt-adv-heading7404_af72dc-e7[data-kb-block=\"kb-adv-heading7404_af72dc-e7\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_af72dc-e7 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_af72dc-e7[data-kb-block=\"kb-adv-heading7404_af72dc-e7\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_af72dc-e7 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_af72dc-e7[data-kb-block=\"kb-adv-heading7404_af72dc-e7\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 id=\"return-posts-by-date\" class=\"kt-adv-heading7404_af72dc-e7 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_af72dc-e7\"><strong>Returns posts dated December 12, 2012<\/strong><\/h3>\n\n\n\n<p>Source: <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#date-parameters\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#date-parameters<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\n   if ( $ql_id == 5283 ) {\n\n\n      $query['date_query'] = array(\n         array(\n            'year' =&gt; 2012,\n            'month' =&gt; 12,\n            'day' =&gt; 12,\n         ),\n      );\n   }\n   \n   return $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_6dc6fb-cf, .wp-block-kadence-advancedheading.kt-adv-heading7404_6dc6fb-cf[data-kb-block=\"kb-adv-heading7404_6dc6fb-cf\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_6dc6fb-cf mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_6dc6fb-cf[data-kb-block=\"kb-adv-heading7404_6dc6fb-cf\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_6dc6fb-cf img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_6dc6fb-cf[data-kb-block=\"kb-adv-heading7404_6dc6fb-cf\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 id=\"display-posts-with-custom-field-key-and-value\" class=\"kt-adv-heading7404_6dc6fb-cf wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_6dc6fb-cf\">Display posts where the custom field key is \u2018color\u2019 and the custom field value IS \u2018blue\u2019<\/h3>\n\n\n\n<p>Source: <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#custom-field-post-meta-parameters\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#custom-field-post-meta-parameters<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\n   if ( $ql_id == 5283 ) {\n\n\n      $query['meta_key'] = 'color';\n      $query['meta_value'] = 'blue';\n      $query['meta_compare'] = '=';\n   }\n   \n   return $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_129b3d-7c, .wp-block-kadence-advancedheading.kt-adv-heading7404_129b3d-7c[data-kb-block=\"kb-adv-heading7404_129b3d-7c\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_129b3d-7c mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_129b3d-7c[data-kb-block=\"kb-adv-heading7404_129b3d-7c\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_129b3d-7c img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_129b3d-7c[data-kb-block=\"kb-adv-heading7404_129b3d-7c\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 id=\"display-posts-with-25-comments-or-more\" class=\"kt-adv-heading7404_129b3d-7c wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_129b3d-7c\"><strong>Display posts with 25 comments or more<\/strong><\/h3>\n\n\n\n<p>Source: <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#comment-parameters\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#comment-parameters<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\n   if ( $ql_id == 5283 ) {\n      $query['post_type'] = 'post';\n      $query['comment_count'] = array(\n         'value' =&gt; 1,\n         'compare' =&gt; '&gt;=',\n      );\n   }\n   \n   return $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_d5f19f-20, .wp-block-kadence-advancedheading.kt-adv-heading7404_d5f19f-20[data-kb-block=\"kb-adv-heading7404_d5f19f-20\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_d5f19f-20 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_d5f19f-20[data-kb-block=\"kb-adv-heading7404_d5f19f-20\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_d5f19f-20 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_d5f19f-20[data-kb-block=\"kb-adv-heading7404_d5f19f-20\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 id=\"display-posts-that-are-not-in-a-category\" class=\"kt-adv-heading7404_d5f19f-20 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_d5f19f-20\">Display posts that are not in a specific category<\/h3>\n\n\n\n<p>Source: <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#category-parameters\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#category-parameters<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\n   if ( $ql_id == 5283 ) {\n      $query['category__not_in'] = 5;\n   }\t\n   \n   return $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_a61f93-f8, .wp-block-kadence-advancedheading.kt-adv-heading7404_a61f93-f8[data-kb-block=\"kb-adv-heading7404_a61f93-f8\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_a61f93-f8 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_a61f93-f8[data-kb-block=\"kb-adv-heading7404_a61f93-f8\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_a61f93-f8 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_a61f93-f8[data-kb-block=\"kb-adv-heading7404_a61f93-f8\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 id=\"display-posts-from-multiple-specific-taxonomies-and-terms\" class=\"kt-adv-heading7404_a61f93-f8 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_a61f93-f8\">Display posts from multiple specific taxonomies and terms<\/h3>\n\n\n\n<p>Source: <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#taxonomy-parameters\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/#taxonomy-parameters<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\n   if ( $ql_id == 5283 ) {\n      $query['tax_query'] = array(\n         'relation' =&gt; 'AND', \/\/ Relation between taxonomies\n         \n         array(\n            'taxonomy' =&gt; 'category',  \/\/ First taxonomy type\n            'field'    =&gt; 'slug',\n            'terms'    =&gt; 'a',         \/\/ Slug of the first taxonomy term\n         ),\n\n         array(\n            'taxonomy' =&gt; 'category',  \/\/ Second taxonomy type\n            'field'    =&gt; 'slug',\n            'terms'    =&gt; 'fruit',     \/\/ Slug of the second taxonomy term\n         ),\n      );\n   }\n\n   return $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_238daf-a6, .wp-block-kadence-advancedheading.kt-adv-heading7404_238daf-a6[data-kb-block=\"kb-adv-heading7404_238daf-a6\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_238daf-a6 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_238daf-a6[data-kb-block=\"kb-adv-heading7404_238daf-a6\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_238daf-a6 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_238daf-a6[data-kb-block=\"kb-adv-heading7404_238daf-a6\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading7404_238daf-a6 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_238daf-a6\">Display posts from author<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\n   if ( $ql_id == 5283 ) {\n     \/\/ Replace 123 with the user ID you want to filter by\n     $query['author'] = 123;\n     \/\/ Or use author__in for multiple users:\n     \/\/ $query['author__in'] = array( 123, 456 );\n   }\n\n   return $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_f1b8f7-f5, .wp-block-kadence-advancedheading.kt-adv-heading7404_f1b8f7-f5[data-kb-block=\"kb-adv-heading7404_f1b8f7-f5\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_f1b8f7-f5 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_f1b8f7-f5[data-kb-block=\"kb-adv-heading7404_f1b8f7-f5\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_f1b8f7-f5 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_f1b8f7-f5[data-kb-block=\"kb-adv-heading7404_f1b8f7-f5\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 id=\"show-related-posts-for-custom-taxonomies\" class=\"kt-adv-heading7404_f1b8f7-f5 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_f1b8f7-f5\">Show Related Posts for Custom Taxonomies<\/h3>\n\n\n\n<p>The Advanced Query Loop block includes an option to <em>Show Related Posts<\/em>, which by default uses the standard post categories and tags to determine related content. If you&#8217;re working with a custom post type and\/or a custom taxonomy, you can use the following snippet to modify the query and show related posts based on a specific taxonomy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\n   if ( $ql_id == 5283 ) {\n      $current_post_id = get_the_ID();\n\n      \/\/ Get the taxonomy terms of the current page\n      $terms = get_the_terms( $current_post_id, 'edownload' ); \/\/Replace 'edownload' with your taxonomy term\n\t\t\n\t  \/\/ Ensure the terms are valid\n      if ( $terms &amp;&amp; ! is_wp_error( $terms ) ) {\n         $term_slugs = wp_list_pluck( $terms, 'slug' );\n\n      \/\/ Return the terms in the tax_query array\n         $query['tax_query'] = array(\n            array(\n               'taxonomy' =&gt; 'edownload',  \/\/Replace 'edownload' with your taxonomy term\n               'field'    =&gt; 'slug',\n               'terms'    =&gt; $term_slugs,\n            ),\n         );\n      }\n   }\n\n   return $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_8d1158-bf, .wp-block-kadence-advancedheading.kt-adv-heading7404_8d1158-bf[data-kb-block=\"kb-adv-heading7404_8d1158-bf\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_8d1158-bf mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_8d1158-bf[data-kb-block=\"kb-adv-heading7404_8d1158-bf\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_8d1158-bf img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_8d1158-bf[data-kb-block=\"kb-adv-heading7404_8d1158-bf\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 id=\"show-only-in-stock-woocommerce-products\" class=\"kt-adv-heading7404_8d1158-bf wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_8d1158-bf\">Show Only In-Stock WooCommerce Products<\/h3>\n\n\n\n<p>By default, Adv Query Loop will display all products regardless of stock status. The following will modify the query so that it only shows in-stock products.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">\/\/ Show only Products that are in-stock\nadd_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\tif ( $ql_id == 149879 ) {  \/\/ &lt;-- change to your Query Loop ID\n\t\t$query['meta_query'] = array(\n\t\t\tarray(\n\t\t\t\t'key'     =&gt; '_stock_status',\n\t\t\t\t'value'   =&gt; 'instock',\n\t\t\t\t'compare' =&gt; '=',\n\t\t\t),\n\t\t);\n\t}\n\treturn $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_9c4852-44, .wp-block-kadence-advancedheading.kt-adv-heading7404_9c4852-44[data-kb-block=\"kb-adv-heading7404_9c4852-44\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_9c4852-44 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_9c4852-44[data-kb-block=\"kb-adv-heading7404_9c4852-44\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_9c4852-44 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_9c4852-44[data-kb-block=\"kb-adv-heading7404_9c4852-44\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading7404_9c4852-44 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_9c4852-44\"><strong>Show Only Woocommerce Products that are on sale<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">\/\/ Show only Products that are on sale\nadd_filter( 'kadence_blocks_pro_query_loop_query_vars', function( $query, $ql_query_meta, $ql_id ) {\n\tif ( $ql_id == 149879 ) {  \/\/ &lt;-- change to your Query Loop ID\n\t  \/\/ Get all product IDs on sale (WooCommerce core helper)\n          $sale_ids = wc_get_product_ids_on_sale();\n\n          if ( ! empty( $sale_ids ) ) {\n              \/\/ Force using these IDs\n              $query['post__in'] = $sale_ids;\n\n              \/\/ Optionally, ensure it\u2019s querying products\n              $query['post_type'] = 'product';\n          } else {\n            \/\/ If no products on sale, force an empty result\n            $query['post__in'] = [0];\n          }\n\t}\n\treturn $query;\n}, 10, 3 );<\/code><\/pre>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading7404_453465-85, .wp-block-kadence-advancedheading.kt-adv-heading7404_453465-85[data-kb-block=\"kb-adv-heading7404_453465-85\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading7404_453465-85 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading7404_453465-85[data-kb-block=\"kb-adv-heading7404_453465-85\"] mark.kt-highlight{font-style:normal;color:#f76a0c;-webkit-box-decoration-break:clone;box-decoration-break:clone;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.wp-block-kadence-advancedheading.kt-adv-heading7404_453465-85 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading7404_453465-85[data-kb-block=\"kb-adv-heading7404_453465-85\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 id=\"enable-relevanssi-integration\" class=\"kt-adv-heading7404_453465-85 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading7404_453465-85\">Enable Relevanssi Integration<\/h3>\n\n\n\n<p>The text search feature for Adv Query Loop uses the native WordPress search function which only considers the <strong>post title<\/strong> and <strong>post content<\/strong> values. Additional details such as custom post meta values, categories, and tags are not included so native searches will not consider these additional fields.  <strong>Relevanssi<\/strong> replaces the native WP search functionality and gives you greater control over your search results. To learn more about Relevanssi, see their <a href=\"https:\/\/wordpress.org\/plugins\/relevanssi\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">plugin page<\/a> or the <a href=\"https:\/\/www.relevanssi.com\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">official website<\/a>.<\/p>\n\n\n\n<p>Adding the following code snippet will enable the Kadence Advance Query Loop to use the Relevanssi search query for a specific Advanced Query Loop block:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter('kadence_blocks_pro_query_loop_query_vars', function( $query_args, $ql_query_meta, $ql_id ){\n\n     if ( $ql_id == 5283 &amp;&amp; function_exists( 'relevanssi_do_query' ) &amp;&amp; isset( $query_args['s'] ) ) {\n          $query_args['relevanssi'] = true;\n     }\n\n     return $query_args; \n}, 10, 3);<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Advanced Query Loop block (Kadence Blocks Pro) provides settings to create a custom query loop. However, sometimes, you need to alter the query beyond the capabilities of the Advanced Query Loop&#8217;s settings. In these cases, you can add a code snippet to alter the WordPress Query object. You can add PHP code to your&#8230;<\/p>\n","protected":false},"author":143301,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kadence_starter_templates_imported_post":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"doc_category":[420],"doc_tag":[],"knowledge_base":[7],"class_list":["post-7404","docs","type-docs","status-publish","hentry","doc_category-blocks-advanced","knowledge_base-kadence-blocks"],"year_month":"2026-05","word_count":1081,"total_views":"14388","reactions":{"happy":"2","normal":"0","sad":"3"},"author_info":{"display_name":"gilberthernandez","author_link":"https:\/\/www.kadencewp.com\/help-center\/author\/gilberthernandez\/"},"doc_category_info":[{"term_name":"Advanced","term_url":"https:\/\/www.kadencewp.com\/help-center\/knowledge-base\/kadence-blocks\/blocks-advanced\/"}],"doc_tag_info":[],"knowledge_base_info":[{"term_name":"Kadence Blocks","term_url":"https:\/\/www.kadencewp.com\/help-center\/knowledge-base\/kadence-blocks\/","term_slug":"kadence-blocks"}],"knowledge_base_slug":["kadence-blocks"],"taxonomy_info":{"doc_category":[{"value":420,"label":"Advanced"}],"knowledge_base":[{"value":7,"label":"Kadence Blocks"}]},"featured_image_src_large":false,"comment_info":0,"_links":{"self":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/7404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/users\/143301"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/comments?post=7404"}],"version-history":[{"count":24,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/7404\/revisions"}],"predecessor-version":[{"id":16216,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/7404\/revisions\/16216"}],"wp:attachment":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/media?parent=7404"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_category?post=7404"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_tag?post=7404"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/knowledge_base?post=7404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}