{"id":15741,"date":"2025-10-17T10:10:59","date_gmt":"2025-10-17T10:10:59","guid":{"rendered":"https:\/\/www.kadencewp.com\/help-center\/?post_type=docs&#038;p=15741"},"modified":"2026-04-22T16:24:34","modified_gmt":"2026-04-22T16:24:34","password":"","slug":"custom-queries-for-portfolio-grid-carousel-block","status":"publish","type":"docs","link":"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/custom-queries-for-portfolio-grid-carousel-block\/","title":{"rendered":"Custom Queries for the Portfolio Grid\/Carousel Block (Filter)"},"content":{"rendered":"\n<p>The <a href=\"https:\/\/www.kadencewp.com\/help-center\/docs\/kadence-blocks\/portfolio-grid-carousel-block\/\">Portfolio 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_portfolio_grid_query_args<\/code> filter.<\/p>\n\n\n<style>.kb-table-of-content-nav.kb-table-of-content-id15741_78b9c8-00 .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-id15741_78b9c8-00 .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-id15741_78b9c8-00 .kb-table-of-contents-title{font-weight:regular;font-style:normal;}.kb-table-of-content-nav.kb-table-of-content-id15741_78b9c8-00 .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-heading15741_a7353d-9c, .wp-block-kadence-advancedheading.kt-adv-heading15741_a7353d-9c[data-kb-block=\"kb-adv-heading15741_a7353d-9c\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15741_a7353d-9c mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15741_a7353d-9c[data-kb-block=\"kb-adv-heading15741_a7353d-9c\"] 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-heading15741_a7353d-9c img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15741_a7353d-9c[data-kb-block=\"kb-adv-heading15741_a7353d-9c\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h2 class=\"kt-adv-heading15741_a7353d-9c wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15741_a7353d-9c\">Adding Custom CSS Classes to Portfolio Grid\/Carousel Blocks<\/h2>\n\n\n\n<p>The examples in this document rely on the Portfolio Grid\/Carousel Block having a <strong>Custom CSS Class<\/strong> applied. To add a Custom CSS Class, select the Portfolio 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-image15741_516775-c2 .kb-image-has-overlay:after{opacity:0.3;}<\/style>\n<figure class=\"wp-block-kadence-image kb-image15741_516775-c2 size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"613\" src=\"https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/10\/Add-Page-\u2039-Bonn-Joel-\u2014-WordPress-2025-10-17-at-5.39.09-PM-1024x613.jpg\" alt=\"\" class=\"kb-img wp-image-15738\" srcset=\"https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/10\/Add-Page-\u2039-Bonn-Joel-\u2014-WordPress-2025-10-17-at-5.39.09-PM-1024x613.jpg 1024w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/10\/Add-Page-\u2039-Bonn-Joel-\u2014-WordPress-2025-10-17-at-5.39.09-PM-300x180.jpg 300w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/10\/Add-Page-\u2039-Bonn-Joel-\u2014-WordPress-2025-10-17-at-5.39.09-PM-768x460.jpg 768w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/10\/Add-Page-\u2039-Bonn-Joel-\u2014-WordPress-2025-10-17-at-5.39.09-PM-1536x920.jpg 1536w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/10\/Add-Page-\u2039-Bonn-Joel-\u2014-WordPress-2025-10-17-at-5.39.09-PM-2048x1226.jpg 2048w, https:\/\/www.kadencewp.com\/help-center\/wp-content\/uploads\/sites\/14\/2025\/10\/Add-Page-\u2039-Bonn-Joel-\u2014-WordPress-2025-10-17-at-5.39.09-PM-360x216.jpg 360w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n<style>.wp-block-kadence-advancedheading.kt-adv-heading15741_3f149b-aa, .wp-block-kadence-advancedheading.kt-adv-heading15741_3f149b-aa[data-kb-block=\"kb-adv-heading15741_3f149b-aa\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15741_3f149b-aa mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15741_3f149b-aa[data-kb-block=\"kb-adv-heading15741_3f149b-aa\"] 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-heading15741_3f149b-aa img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15741_3f149b-aa[data-kb-block=\"kb-adv-heading15741_3f149b-aa\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading15741_3f149b-aa wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15741_3f149b-aa\">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_pro_portfolio_grid_query_args', function( $args, $attributes ) {\n\n    \/\/ Target a specific Portfolio 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-heading15741_f51218-c8, .wp-block-kadence-advancedheading.kt-adv-heading15741_f51218-c8[data-kb-block=\"kb-adv-heading15741_f51218-c8\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15741_f51218-c8 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15741_f51218-c8[data-kb-block=\"kb-adv-heading15741_f51218-c8\"] 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-heading15741_f51218-c8 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15741_f51218-c8[data-kb-block=\"kb-adv-heading15741_f51218-c8\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading15741_f51218-c8 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15741_f51218-c8\">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_pro_portfolio_grid_query_args', function( $args, $attributes ) {\n\n    \/\/ Target a specific Portfolio 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-heading15741_7964a2-d5, .wp-block-kadence-advancedheading.kt-adv-heading15741_7964a2-d5[data-kb-block=\"kb-adv-heading15741_7964a2-d5\"]{font-style:normal;}.wp-block-kadence-advancedheading.kt-adv-heading15741_7964a2-d5 mark.kt-highlight, .wp-block-kadence-advancedheading.kt-adv-heading15741_7964a2-d5[data-kb-block=\"kb-adv-heading15741_7964a2-d5\"] 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-heading15741_7964a2-d5 img.kb-inline-image, .wp-block-kadence-advancedheading.kt-adv-heading15741_7964a2-d5[data-kb-block=\"kb-adv-heading15741_7964a2-d5\"] img.kb-inline-image{width:150px;vertical-align:baseline;}<\/style>\n<h3 class=\"kt-adv-heading15741_7964a2-d5 wp-block-kadence-advancedheading\" data-kb-block=\"kb-adv-heading15741_7964a2-d5\">Explore More Examples<\/h3>\n\n\n\n<p>Even though the <strong>Query Loop (Advanced) Block<\/strong> and the <strong>Portfolio 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 Portfolio Grid\/Carousel Block<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Portfolio 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":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-15741","docs","type-docs","status-publish","hentry","doc_category-blocks-advanced","knowledge_base-kadence-blocks"],"year_month":"2026-04","word_count":439,"total_views":"970","reactions":{"happy":"0","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\/15741","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=15741"}],"version-history":[{"count":3,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/15741\/revisions"}],"predecessor-version":[{"id":15744,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/docs\/15741\/revisions\/15744"}],"wp:attachment":[{"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/media?parent=15741"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_category?post=15741"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/doc_tag?post=15741"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/www.kadencewp.com\/help-center\/wp-json\/wp\/v2\/knowledge_base?post=15741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}