Archived topic
Few questions regarding GB query block
5 replies · Started by Fabien on June 17, 2022
Hi,
I have few questions regarding GB query block :
1. Can you use shortcode to pull dynamic content within a post ?
2. I've seen that you release the following filter generateblocks_query_loop_args. Can you please give some instructions / examples ?
3. When using Dynamic Data > Post Meta field, values are not prepopulated (ie. the dropdown is empty). Is it because I created my fields using ACF ?
Thanks a lot !
Also :
4. Local templates are great but it's too bad they don't sync : "Local templates do not update automatically. For example, if you insert a Local Template to your page, then change the source Local Template, it will not make changes to the one we added to our page."
Will there be an option to sync in the future ? This could be pretty useful for the Query Block !
Hi Fabien,
1. Are you referring to creating a shortcode that returns a post meta field? Yes, this is possible. Here’s an article showing a sample: https://storyteller.co.za/how-to-create-a-shortcode-using-advanced-custom-fields-data/#:~:text=to%20search%20again.-,How%20do%20I%20create,-a%20shortcode%20that
2. Here’s an example of how to use it: https://community.generateblocks.com/t/use-gb-query-loop-for-related-post/688/2#:~:text=1.5.0%2Dbeta.2-,%2C%20you%E2%80%99ll%20be%20able,-to%20do%20this
Basically, generateblocks_query_loop_args filter allows you to alter specific “settings” if a Query Loop Block. So, for instance, if I add class my-class-name to the Grid Block of the Query Loop Block, using the code below, $query_args['posts_per_page'] = 1; allows me to set the post per page setting of the Query Loop. You can add var_dump($query_args); to the code below to see the values of $query_args
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-class-name' ) !== false ) {
$query_args['posts_per_page'] = 1;
}
return $query_args;
}, 10, 2 );
3. Certain ACF fields should be retrievable through Headline Blocks, and Image Blocks. What type of ACF field are you retrieving? If it's not a text or an image for instance, maybe you can use the shortcode sample in #1.
Hope this helps!
4. Yes, it doesn’t update by default in the same way Templates from the Template/Pattern library doesn’t: https://docs.generateblocks.com/article/template-library-overview/#local-templates
You may raise a feature request here for such a functionality: https://community.generateblocks.com/c/feature-requests/6
Hope this clarifies!
Hi @Fernando,
Thanks for your replies. Please find my comment below :
1. I've created a shortcode that returns a meta field. While the shortcode works well in my content template (cf. single post), it doesn't work when using the Query Block on an other page (here, the homepage). I've added my shortcode (pretty basic as you will see) in the private information.
2. Thanks, I will have a look
3. It doesn't work (ie. the list is not populated), I need to manually enter the name of the meta field
4. Thanks, I've raised a featured request
Hi there,
1. Check the ACF documentation about getting fields in a Loop, you may need to pass the ID to it eg.
https://stackoverflow.com/a/58106091
3. At this time GB integrates with core custom fields, we will be adding more advanced integrations later.
For the time being, if you want to include your ACF fields in the list, then see here:
https://github.com/tomusborne/generateblocks/issues/582#issuecomment-1160982965