- This topic has 7 replies, 3 voices, and was last updated 3 years, 5 months ago by
David.
-
AuthorPosts
-
November 8, 2022 at 9:42 pm #2407406
Sabbir
Hi.
Is there any way to change the query loop post-change daily basis?
I want to show this option in today’s daily prayer section.
Thanks
November 8, 2022 at 10:11 pm #2407429Fernando Customer Support
Hi Sabbir,
There isn’t a way to do this through GenerateBlocks settings. What you can do however is to randomize it on each page load.
To do so, add
cu-randomize-queryto the class list of the Grid Block inside the Query Loop Block. Then, add this snippet:add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'cu-randomize-query' ) !== false ) { $query_args['orderby'] = 'rand'; } return $query_args; }, 10, 2 );Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
November 8, 2022 at 11:16 pm #2407461Sabbir
Hi,
Thank you!
Is it work for one block/section or the whole site?
I just want to do it for 1 section, which is the daily prayers section.
Also, I can’t try the code, here is the error: https://prnt.sc/j26WyWEGXVLA
Also, check if it helps: https://wordpress.stackexchange.com/questions/199619/random-post-once-per-day
November 9, 2022 at 12:37 am #2407558Fernando Customer Support
It should only work for Query Loops Blocks that have the class
cu-randomize-query.Can you test the code above? I updated it.
With regards to transients, it works by caching the instance of a Query. To do so, you’ll need to alter the code in the plugin itself.
An alternative you can do is to use a Caching plugin capable of Object caching. See here for more info about Object cache: https://wp-rocket.me/blog/object-caching-use-wordpress/#section-2:~:text=I%20Want%20This!-,So%20What%20is%20Object%20Caching%3F,-Object%20caching%20involves
It basically stores database queried results. Most Caching plugins have a Cache Lifespan, that is, the cache is refreshed after a certain time. WP Rocket for instance I believe does this. If so, you can set it through automatically refresh the cache every 24 hours. I’m not entirely sure if this will work though, but theoretically, it could.
November 9, 2022 at 3:43 am #2407811Sabbir
I try the code, it’s working now.
Is there any way to change it after 24 hours? The prayer changes randomly after refresh.
Or
I use siteground cache plugin, is there any guide to do this?
November 9, 2022 at 5:33 am #2407980David
StaffCustomer SupportHi there,
speak to your hosting company, explain that you want to cache that page for 24 hrs.
they should be able to assist with that.November 9, 2022 at 8:46 am #2408521Sabbir
Thanks David.
November 9, 2022 at 8:47 am #2408524David
StaffCustomer SupportLet us know how you get on!
-
AuthorPosts
- You must be logged in to reply to this topic.