{"id":14897,"date":"2025-09-17T23:31:08","date_gmt":"2025-09-17T23:31:08","guid":{"rendered":"https:\/\/www.kadencewp.com\/help-center\/?post_type=docs&#038;p=14897"},"modified":"2026-04-22T16:28:57","modified_gmt":"2026-04-22T16:28:57","password":"","slug":"custom-queries-post-grid-carousel-block","status":"publish","type":"docs","link":"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/custom-queries-post-grid-carousel-block\/","title":{"rendered":"Custom Queries for the Post Grid\/Carousel Block (Filter)"},"content":{"rendered":"\n<p>The <a href=\"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/kadence-blocks-post-grid-carousel-block\/\">Post Grid\/Carousel<\/a> block (<a href=\"https:\/\/www.kadencewp.com\/kadence-blocks\/pro\/\">Kadence Blocks Pro<\/a>) provides settings to display posts in a grid or carousel 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 <a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_query\/\" target=\"_blank\" rel=\"noreferrer noopener\">WordPress Query object<\/a> directly. You can add <strong>PHP<\/strong> <strong>code<\/strong> 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 <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> <code>functions.php<\/code> file.<\/p>\n\n\n\n<p>If you want to modify the query arguments, you can make use of the <code>kadence_blocks_pro_posts_grid_query_args<\/code> filter. <\/p>\n\n\n<style>.kb-table-of-content-nav.kb-table-of-content-id14897_c87fce-42 .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-id14897_c87fce-42 .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-id14897_c87fce-42 .kb-table-of-contents-title{font-weight:regular;font-style:normal;}.kb-table-of-content-nav.kb-table-of-content-id14897_c87fce-42 .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-heading14897_186d22-19, .wp-block-kadence-advancedheading.kt-adv-heading14897_186d22-19[data-kb-block=\"kb-adv-heading14897_186d22-19\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading14897_186d22-19 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading14897_186d22-19[data-kb-block=\"kb-adv-heading14897_186d22-19\"] 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-heading14897_186d22-19 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading14897_186d22-19[data-kb-block=\"kb-adv-heading14897_186d22-19\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h2 class=\"kt-adv-heading14897_186d22-19 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading14897_186d22-19\">Adding Custom CSS Classes to Post Grid\/Carousel Blocks<\/h2>\n\n\n\n<p>The examples in this document rely on the Post Grid\/Carousel Block having a <strong>Custom CSS Class<\/strong> applied. To add a Custom CSS Class, select the Post Grid\/Carousel Block in the WordPress Editor, then navigate to <strong>Block Settings \u2192 Advanced Tab \u2192 Advanced \u2192 Additional CSS Class(es)<\/strong> and enter your class.<\/p>\n\n\n<style>.kb-image14897_367ed4-f3 .kb-image-has-overlay:after{opacity:0.3;}<\/style>\n<figure class=\"wp-block-kadence-image kb-image14897_367ed4-f3 size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"2560\" height=\"1575\" src=\"https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/09\/Custom-CSS-Classes-on-Post-Grids-scaled.jpg\" alt=\"Custom CSS Classes on Post Grids\" class=\"kb-img wp-image-14902\" srcset=\"https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/09\/Custom-CSS-Classes-on-Post-Grids-scaled.jpg 2560w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/09\/Custom-CSS-Classes-on-Post-Grids-300x185.jpg 300w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/09\/Custom-CSS-Classes-on-Post-Grids-1024x630.jpg 1024w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/09\/Custom-CSS-Classes-on-Post-Grids-768x472.jpg 768w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/09\/Custom-CSS-Classes-on-Post-Grids-1536x945.jpg 1536w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/09\/Custom-CSS-Classes-on-Post-Grids-2048x1260.jpg 2048w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/09\/Custom-CSS-Classes-on-Post-Grids-360x221.jpg 360w\" sizes=\"auto, (max-width: 2560px) 100vw, 2560px\" \/><\/figure>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading14897_873ba1-e2, .wp-block-kadence-advancedheading.kt-adv-heading14897_873ba1-e2[data-kb-block=\"kb-adv-heading14897_873ba1-e2\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading14897_873ba1-e2 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading14897_873ba1-e2[data-kb-block=\"kb-adv-heading14897_873ba1-e2\"] 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-heading14897_873ba1-e2 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading14897_873ba1-e2[data-kb-block=\"kb-adv-heading14897_873ba1-e2\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading14897_873ba1-e2 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading14897_873ba1-e2\">Example 1: Query Multiple Post Types<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">add_filter( 'kadence_blocks_pro_posts_grid_query_args', function( $args, $attributes ) {\n\n    \/\/ Target a specific Post Grid\/Carousel block using a custom class\n    if ( isset( $attributes['className'] ) &amp;&amp; strpos( $attributes['className'], 'YOUR-CUSTOM-CLASS' ) !== false ) {\n        \n        \/\/ Show posts from multiple post types. Adjust the array as needed.\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    }\n\n    return $args;\n\n}, 10, 2 );<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Targets only blocks with the specified class (<code>YOUR-CUSTOM-CLASS<\/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-heading14897_31b406-13, .wp-block-kadence-advancedheading.kt-adv-heading14897_31b406-13[data-kb-block=\"kb-adv-heading14897_31b406-13\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading14897_31b406-13 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading14897_31b406-13[data-kb-block=\"kb-adv-heading14897_31b406-13\"] 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-heading14897_31b406-13 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading14897_31b406-13[data-kb-block=\"kb-adv-heading14897_31b406-13\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading14897_31b406-13 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading14897_31b406-13\">Example 2: Show Only Posts with a Populated Custom Field<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">add_filter( 'kadence_blocks_pro_posts_grid_query_args', function( $args, $attributes ) {\n\n    \/\/ Target a specific Post Grid\/Carousel block using a custom class\n    if ( isset( $attributes['className'] ) &amp;&amp; strpos( $attributes['className'], 'YOUR-CUSTOM-CLASS' ) !== false ) {\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, 2 );<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Targets blocks with the specified class (<code>YOUR-CUSTOM-CLASS<\/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-heading14897_742bf8-28, .wp-block-kadence-advancedheading.kt-adv-heading14897_742bf8-28[data-kb-block=\"kb-adv-heading14897_742bf8-28\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading14897_742bf8-28 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading14897_742bf8-28[data-kb-block=\"kb-adv-heading14897_742bf8-28\"] 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-heading14897_742bf8-28 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading14897_742bf8-28[data-kb-block=\"kb-adv-heading14897_742bf8-28\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading14897_742bf8-28 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading14897_742bf8-28\">Explore More Examples<\/h3>\n\n\n\n<p>Even though the <strong>Query Loop (Advanced) Block<\/strong> and the <strong>Post Grid\/Carousel 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 Post Grid\/Carousel Block.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Post Grid\/Carousel block (Kadence Blocks Pro) provides settings to display posts in a grid or carousel 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 WordPress Query object directly. You can add PHP code to your site&#8230;<\/p>\n","protected":false},"author":148263,"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-14897","docs","type-docs","status-publish","hentry","doc_category-blocks-advanced","knowledge_base-kadence-blocks"],"year_month":"2026-04","word_count":439,"total_views":"2046","reactions":{"happy":"2","normal":"0","sad":"0"},"author_info":{"display_name":"victormonk","author_link":"https:\/\/www.kadencewp.com\/help-center\/author\/victormonk\/"},"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\/14897","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\/148263"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/comments?post=14897"}],"version-history":[{"count":9,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/14897\/revisions"}],"predecessor-version":[{"id":15737,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/14897\/revisions\/15737"}],"wp:attachment":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/media?parent=14897"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_category?post=14897"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_tag?post=14897"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/knowledge_base?post=14897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}