- This topic has 4 replies, 2 voices, and was last updated 3 years, 2 months ago by
Manzelov.
-
AuthorPosts
-
February 17, 2023 at 9:51 am #2537109
Manzelov
Hi,
I am trying to setup a filter on Archive pages using GenerateBlocks Query Loop and with the help of the WP Grid Builder.
I am following is a very nice totorial published here, which is actually based on a code adapted from your support forum – https://generatepress.com/forums/topic/how-to-set-up-a-custom-parameter/#post-2302691
The implementation works just fine but only if the GenerateBlocks Query Loop is not located on an archive page and ‘Inherit query from template’ is turned off. In such case the filter is not displaying at all.
I have created a Block element of Loop type containig a GenerateBlocks Query Loop and I would like to be able to use this element and achieve the same result on any archive page, i.e. where the GenerateBlocks Query Loop is not located on an archive page and ‘Inherit query from template’ is turned on.
I hope this is possible. Thank you!
February 17, 2023 at 1:59 pm #2537331Ying
StaffCustomer SupportHi there,
Your example link doesn’t work, but I get your idea.
In your case, you need to modify the archive loop itself, not the query loop block.
So try this snippet, just modify the date.
function modify_archive_query($query) { if ($query->is_archive() && $query->is_main_query()) { $query->set('date_query', array( array( 'after' => 'February 10, 2023', 'inclusive' => true ) )); } } add_action('pre_get_posts', 'modify_archive_query');February 17, 2023 at 2:41 pm #2537378Manzelov
Thank you, Ying!
I am actually using this code snippet:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'wpgb-query' ) !== false ) { $query_args['wp_grid_builder'] = 'wpgb-content-1'; } return $query_args; }, 10, 2 );My filters will be based on post custom taxonomies and the filter fascet is created with the WP Grid Builder plugin.
I would like for these filters are to work on all archive template pages, like categories, tags, and mainly custom taxonomy archive pages, all of which are based on the
is_archive().Could you please help me ‘merge’ the code snippet suggested by you with mine?
February 17, 2023 at 2:51 pm #2537387Ying
StaffCustomer SupportIn this case, it’s better to reach out to the plugin’s support to make sure the right code is being used.
They should be able to help with general archive loop arguments modification.
February 17, 2023 at 2:52 pm #2537388Manzelov
Thank you!
-
AuthorPosts
- You must be logged in to reply to this topic.