function filter_specific_query_loop($query) {
// Check if this is an admin query or not the main query
if (is_admin() || !$query->is_main_query()) {
return;
}
// Check for the presence of the custom query parameter
if (isset($query->query_vars['custom_query_loop']) && $query->query_vars['custom_query_loop']) {
// Modify the query to include multiple post types
$query->set('post_type', array('post', 'restaurants', 'activities', 'equipment','recipes'));
}
}
add_action('pre_get_posts', 'filter_specific_query_loop');
// Add a filter to include the custom query parameter when rendering the block
function add_custom_query_var($block_content, $block) {
if ($block['blockName'] === 'core/query') {
if (isset($block['attrs']['className']) && strpos($block['attrs']['className'], 'custom-query-loop') !== false) {
add_filter('query_vars', function ($query_vars) {
$query_vars[] = 'custom_query_loop';
return $query_vars;
});
}
}
return $block_content;
}
add_filter('render_block', 'add_custom_query_var', 10, 2);
I added custom class name: custom-query-loop to the query loop (located on home page). When I preview my page however, I only see one post type from the query loop.
Am I doing something wrong? My site is not live yet.
Thank you in advance for help!
]]>I’ve seen others struggle with the same issue but have yet to find a straight answer to how to make it work.
I’m using the WP theme Twenty Twentyfour in combination with Pods and have created a CPT with custom fields. In Twenty Twentyfour, you can easily create templates for individual posts and archives. Templates work as intended for individual posts, including auto templates. However, I still need to figure out a solution for archive templates. The archive is certainly displayed, but only, e.g., regular headings.
I have activated the Excerpt option in the “Advanced Tab ” and tried enabling “Auto template” with “Filter: the_excerpt.”
So the Pods Blocks display nothing, and nor does the Auto template.
My idea is to use IF conditional tags to show with an icon, e.g., if some PDF document is attached to the post (one of the custom fields).
As an experiment, I have now tried the Plugin “Meta Field Block,” and for some reason, that works, but the native Pods blocks don’t. Of course, I would like to get the native Pods blocks to work, even in the Archive templates, but how?
]]>I have a WooCommerce website, where on the products pages, I manually added a GeneratePress hook after the product’s info in order to display similar products in a GenerateBlocks Query Loop (products that have the same category).
Just before this loop I have a title that says ‘You may also like’.
I was wondering if it was possible to hide the title if there are no other products in the product’s category (so no products to display)?
Thanks!
]]>Database table “ulikemeta” with the meta key “count_total_like” in which, there is a column called “item_id” where the post_id is referenced and a column called “meta_group” where value is indicated as “post”.
I’m stumped…any pointers? I’d like to make sure this works before getting the Pro version if possible. I’d appreciate any help you can offer. Thanks!
]]>I have added the code of the query loop below, maybe it is helpful? Any support would be greatly appreciated.
<!-- wp:group {"align":"wide","layout":{"type":"flex","orientation":"vertical","justifyContent":"center"}} --><div class="wp-block-group alignwide"><!-- wp:query {"queryId":31,"query":{"perPage":30,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true},"metadata":{"categories":["posts"],"patternName":"core/fullwidth-posts-with-uppercase-titles","name":"Fullwidth posts with uppercase titles"},"align":"full","layout":{"type":"default"}} --><div class="wp-block-query alignfull"><!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"0","right":"0","bottom":"0","left":"0"}}},"layout":{"type":"default"}} --><div class="wp-block-group alignfull" style="padding-top:0;padding-right:0;padding-bottom:0;padding-left:0"><!-- wp:post-template {"style":{"typography":{"textTransform":"none"}}} --><!-- wp:group {"style":{"border":{"bottom":{"color":"var:preset|color|contrast","width":"1px"}}},"layout":{"type":"default"}} --><div class="wp-block-group" style="border-bottom-color:var(--wp--preset--color--contrast);border-bottom-width:1px"><!-- wp:group {"style":{"spacing":{"padding":{"top":"16px","right":"16px","bottom":"16px","left":"16px"}}},"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"space-between"}} --><div class="wp-block-group" style="padding-top:16px;padding-right:16px;padding-bottom:16px;padding-left:16px"><!-- wp:group {"style":{"spacing":{"blockGap":"4px"}},"layout":{"type":"flex","flexWrap":"nowrap"}} --><div class="wp-block-group"><!-- wp:paragraph --><p>✴?</p><!-- /wp:paragraph --><!-- wp:post-date {"textAlign":"left","format":"M j, Y","style":{"spacing":{"margin":{"top":"0","right":"0","bottom":"0","left":"0"}},"elements":{"link":{"color":{"text":"var:preset|color|contrast"}}},"typography":{"textTransform":"uppercase"}},"textColor":"contrast","fontSize":"small"} /--></div><!-- /wp:group --><!-- wp:post-terms {"term":"category","prefix":"✴? ","style":{"elements":{"link":{"color":{"text":"var:preset|color|contrast"}}},"typography":{"textTransform":"uppercase"}},"textColor":"contrast"} /--></div><!-- /wp:group --></div><!-- /wp:group --><!-- wp:group {"style":{"spacing":{"padding":{"top":"16px","bottom":"var:preset|spacing|70","right":"16px","left":"16px"}}},"layout":{"type":"flex","orientation":"vertical"}} --><div class="wp-block-group" style="padding-top:16px;padding-right:16px;padding-bottom:var(--wp--preset--spacing--70);padding-left:16px"><!-- wp:post-title {"isLink":true,"style":{"spacing":{"margin":{"top":"0","right":"0","bottom":"0","left":"0"}},"layout":{"selfStretch":"fit"},"typography":{"fontStyle":"normal","fontWeight":"500","lineHeight":"1.1","textTransform":"uppercase","fontSize":"1.7rem"},"elements":{"link":{"color":{"text":"var:preset|color|contrast"}}}},"textColor":"contrast"} /--></div><!-- /wp:group --><!-- /wp:post-template --></div><!-- /wp:group --><!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|30","bottom":"var:preset|spacing|30","right":"16px","left":"16px"},"margin":{"top":"0","bottom":"0"}}},"layout":{"type":"default"}} --><div class="wp-block-group" style="margin-top:0;margin-bottom:0;padding-top:var(--wp--preset--spacing--30);padding-right:16px;padding-bottom:var(--wp--preset--spacing--30);padding-left:16px"><!-- wp:query-pagination {"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"left"}} --><!-- wp:query-pagination-previous {"label":"Previous","style":{"typography":{"textTransform":"uppercase"}},"fontSize":"small"} /--><!-- wp:query-pagination-next {"label":"Next","style":{"typography":{"textTransform":"uppercase"}},"fontSize":"small"} /--><!-- /wp:query-pagination --></div><!-- /wp:group --></div><!-- /wp:query --></div><!-- /wp:group -->
]]><!-- wp:group {"align":"wide","layout":{"type":"flex","orientation":"vertical","justifyContent":"center"}} -->
<div class="wp-block-group alignwide"><!-- wp:query {"queryId":31,"query":{"perPage":30,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":true},"metadata":{"categories":["posts"],"patternName":"core/fullwidth-posts-with-uppercase-titles","name":"Fullwidth posts with uppercase titles"},"align":"full","layout":{"type":"default"}} -->
<div class="wp-block-query alignfull"><!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"0","right":"0","bottom":"0","left":"0"}}},"layout":{"type":"default"}} -->
<div class="wp-block-group alignfull" style="padding-top:0;padding-right:0;padding-bottom:0;padding-left:0"><!-- wp:post-template {"style":{"typography":{"textTransform":"none"}}} -->
<!-- wp:group {"style":{"border":{"bottom":{"color":"var:preset|color|contrast","width":"1px"}}},"layout":{"type":"default"}} -->
<div class="wp-block-group" style="border-bottom-color:var(--wp--preset--color--contrast);border-bottom-width:1px"><!-- wp:group {"style":{"spacing":{"padding":{"top":"16px","right":"16px","bottom":"16px","left":"16px"}}},"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"space-between"}} -->
<div class="wp-block-group" style="padding-top:16px;padding-right:16px;padding-bottom:16px;padding-left:16px"><!-- wp:group {"style":{"spacing":{"blockGap":"4px"}},"layout":{"type":"flex","flexWrap":"nowrap"}} -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>✴?</p>
<!-- /wp:paragraph -->
<!-- wp:post-date {"textAlign":"left","format":"M j, Y","style":{"spacing":{"margin":{"top":"0","right":"0","bottom":"0","left":"0"}},"elements":{"link":{"color":{"text":"var:preset|color|contrast"}}},"typography":{"textTransform":"uppercase"}},"textColor":"contrast","fontSize":"small"} /--></div>
<!-- /wp:group -->
<!-- wp:post-terms {"term":"category","prefix":"✴? ","style":{"elements":{"link":{"color":{"text":"var:preset|color|contrast"}}},"typography":{"textTransform":"uppercase"}},"textColor":"contrast"} /--></div>
<!-- /wp:group --></div>
<!-- /wp:group -->
<!-- wp:group {"style":{"spacing":{"padding":{"top":"16px","bottom":"var:preset|spacing|70","right":"16px","left":"16px"}}},"layout":{"type":"flex","orientation":"vertical"}} -->
<div class="wp-block-group" style="padding-top:16px;padding-right:16px;padding-bottom:var(--wp--preset--spacing--70);padding-left:16px"><!-- wp:post-title {"isLink":true,"style":{"spacing":{"margin":{"top":"0","right":"0","bottom":"0","left":"0"}},"layout":{"selfStretch":"fit"},"typography":{"fontStyle":"normal","fontWeight":"500","lineHeight":"1.1","textTransform":"uppercase","fontSize":"1.7rem"},"elements":{"link":{"color":{"text":"var:preset|color|contrast"}}}},"textColor":"contrast"} /--></div>
<!-- /wp:group -->
<!-- /wp:post-template --></div>
<!-- /wp:group -->
<!-- wp:group {"style":{"spacing":{"padding":{"top":"var:preset|spacing|30","bottom":"var:preset|spacing|30","right":"16px","left":"16px"},"margin":{"top":"0","bottom":"0"}}},"layout":{"type":"default"}} -->
<div class="wp-block-group" style="margin-top:0;margin-bottom:0;padding-top:var(--wp--preset--spacing--30);padding-right:16px;padding-bottom:var(--wp--preset--spacing--30);padding-left:16px"><!-- wp:query-pagination {"layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"left"}} -->
<!-- wp:query-pagination-previous {"label":"Previous","style":{"typography":{"textTransform":"uppercase"}},"fontSize":"small"} /-->
<!-- wp:query-pagination-next {"label":"Next","style":{"typography":{"textTransform":"uppercase"}},"fontSize":"small"} /-->
<!-- /wp:query-pagination --></div>
<!-- /wp:group --></div>
<!-- /wp:query --></div>
<!-- /wp:group -->
]]>I’m developing a site using WordPress full Site Editing theme Twenty Twenty-Four. I want to display multiple (2-4) query loop blocks on one page/post. Each loop queries different custom-post-types and category filters. All displays fine, including the pagination. BUT using the pagination links, i.e. “Next Page” updates all loops. It updates all loops to the same set. In my case, since one of the loops does not contain additional posts, all loops show empty.
I came across coding solutions i.e. giving each loop a separate ID. I’m not versed enough in coding to create my own loops and would like to use the query loop block. Question: is there something I can adjust to make this work in FSE and/or add custom CSS/add some code to a php file?
Thank you. Stephan
]]>This topic is linked to another post I made a few months ago (link here) : back then, I was trying to get WP_Query() to return posts from a subcategory to build a category archive page that would group all posts by subcategory. Basically like this :
Category 1
Subcategory 1A
Subcategory 1B
Category 2 :
Subcategory 2A
Subcategory 2B
My code ended up working – the issue was caused by another plugin. I was working on an old website that still uses the classic editor.
Now, I am trying to see If I can get a similar result with Gutenberg. I guess I could build a block for this, but I was wondering if there is another, more simple, way to do so ? Is there a way to create a query look variation that would allow me to apply an order by subcategory condition, and to display the subcategory names ?
I just want to know what would be the best way to proceed for this type of development as I am still not that familiar with the best practices when building a site with Gutenberg.
Thank in advance for your responses !
]]>