{"id":15495,"date":"2025-10-10T10:44:17","date_gmt":"2025-10-10T10:44:17","guid":{"rendered":"https:\/\/www.kadencewp.com\/help-center\/?post_type=docs&#038;p=15495"},"modified":"2026-04-22T16:25:43","modified_gmt":"2026-04-22T16:25:43","password":"","slug":"custom-queries-for-posts-block","status":"publish","type":"docs","link":"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/custom-queries-for-posts-block\/","title":{"rendered":"Custom Queries for the Posts Block (Filter)"},"content":{"rendered":"\n<p>The&nbsp;<a href=\"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/posts-block\/\" data-type=\"link\" data-id=\"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/posts-block\/\">Posts<\/a>&nbsp;block provides settings to display posts in a grid layout. However, sometimes you need to alter the query beyond the block\u2019s built-in settings. In these cases, you can add a code snippet to modify the&nbsp;<a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/\" target=\"_blank\" rel=\"noreferrer noopener\">WordPress Query object<\/a>&nbsp;directly. You can add&nbsp;<strong>PHP<\/strong>&nbsp;<strong>code<\/strong>&nbsp;to your site using a plugin like&nbsp;<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>&nbsp;or your&nbsp;<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\u2019s<\/a>&nbsp;<code>functions.php<\/code>&nbsp;file.<\/p>\n\n\n\n<p>If you want to modify the query arguments, you can make use of <code>kadence_blocks_posts_query_args<\/code> filter.<\/p>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading15495_6c1130-66, .wp-block-kadence-advancedheading.kt-adv-heading15495_6c1130-66[data-kb-block=\"kb-adv-heading15495_6c1130-66\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15495_6c1130-66 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15495_6c1130-66[data-kb-block=\"kb-adv-heading15495_6c1130-66\"] 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-heading15495_6c1130-66 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15495_6c1130-66[data-kb-block=\"kb-adv-heading15495_6c1130-66\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading15495_6c1130-66 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15495_6c1130-66\">Example 1: Query Multiple Post Types<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_posts_query_args', function( $args ) {\n   if ( get_the_ID() === PAGE_ID ) {\n      $args['post_type'] = array( 'post', 'SECONDARY_POST_TYPE' );\n\n      \/\/ Order posts by publish date\n      $args['orderby'] = 'date';\n      $args['order']   = 'DESC';\n   }\nreturn $args;\n}, 10, 1 );<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Target Posts Block inside page with ID equals to <code>PAGE_ID<\/code><\/li>\n\n\n\n<li>Queries multiple post types (<code>post<\/code> and <code>SECONDARY_POST_TYPE<\/code>).<\/li>\n\n\n\n<li>Orders posts by publish date, newest first.<\/li>\n<\/ul>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading15495_28d1d9-ca, .wp-block-kadence-advancedheading.kt-adv-heading15495_28d1d9-ca[data-kb-block=\"kb-adv-heading15495_28d1d9-ca\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15495_28d1d9-ca mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15495_28d1d9-ca[data-kb-block=\"kb-adv-heading15495_28d1d9-ca\"] 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-heading15495_28d1d9-ca img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15495_28d1d9-ca[data-kb-block=\"kb-adv-heading15495_28d1d9-ca\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading15495_28d1d9-ca wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15495_28d1d9-ca\">Example 2: Show Only Posts with a Populated Custom Field<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_filter( 'kadence_blocks_posts_query_args', function( $args ) {\n\n    \/\/ Target Posts block on a specific page\n   if ( get_the_ID() === PAGE_ID ) {\n\n        \/\/ Specify the post type(s) you want to query\n        $args['post_type'] = 'post';\n\n        \/\/ Only show posts where a specific custom field exists\n        $args['meta_query'] = array(\n            array(\n                'key'     =&gt; 'YOUR_CUSTOM_FIELD',  \/\/ Replace with your field name\n                'compare' =&gt; 'EXISTS',\n            ),\n        );\n\n        \/\/ Order posts by publish date\n        $args['orderby'] = 'date';\n        $args['order']   = 'DESC';\n    }\n\n    return $args;\n\n}, 10, 1 );<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Target Posts Block inside page with ID equals to <code>PAGE_ID<\/code><\/li>\n\n\n\n<li>Filters posts to include only those where the custom field has a value.<\/li>\n\n\n\n<li>Orders posts by publish date, newest first.<\/li>\n<\/ul>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading15495_3b289b-f9, .wp-block-kadence-advancedheading.kt-adv-heading15495_3b289b-f9[data-kb-block=\"kb-adv-heading15495_3b289b-f9\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15495_3b289b-f9 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15495_3b289b-f9[data-kb-block=\"kb-adv-heading15495_3b289b-f9\"] 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-heading15495_3b289b-f9 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15495_3b289b-f9[data-kb-block=\"kb-adv-heading15495_3b289b-f9\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading15495_3b289b-f9 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15495_3b289b-f9\">Explore More Examples<\/h3>\n\n\n\n<p>Even though the <strong>Query Loop (Advanced) Block<\/strong> and the <strong>Posts Block<\/strong> use <span style=\"text-decoration: underline\">different filters and methods<\/span> for accessing the current block, the <strong><a href=\"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/custom-queries-for-advanced-query-loop-block\/\">Custom Queries for the Advanced Query Loop Block (Filter)<\/a><\/strong> documentation provides many examples of the <strong>WordPress Query object<\/strong> being used logically. While these examples cannot be copied and pasted directly, they can be adapted for use with the Posts block.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The&nbsp;Posts&nbsp;block provides settings to display posts in a grid layout. However, sometimes you need to alter the query beyond the block\u2019s built-in settings. In these cases, you can add a code snippet to modify the&nbsp;WordPress Query object&nbsp;directly. You can add&nbsp;PHP&nbsp;code&nbsp;to your site using a plugin like&nbsp;Code Snippets&nbsp;or your&nbsp;child theme\u2019s&nbsp;functions.php&nbsp;file. If you want to modify the&#8230;<\/p>\n","protected":false},"author":116562,"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-15495","docs","type-docs","status-publish","hentry","doc_category-blocks-advanced","knowledge_base-kadence-blocks"],"year_month":"2026-04","word_count":343,"total_views":"1918","reactions":{"happy":"3","normal":"0","sad":"0"},"author_info":{"display_name":"Bonn","author_link":"https:\/\/www.kadencewp.com\/help-center\/author\/bonnjoelelimanco\/"},"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\/15495","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\/116562"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/comments?post=15495"}],"version-history":[{"count":5,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/15495\/revisions"}],"predecessor-version":[{"id":15504,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/15495\/revisions\/15504"}],"wp:attachment":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/media?parent=15495"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_category?post=15495"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_tag?post=15495"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/knowledge_base?post=15495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}