Site logo

[Resolved] Filter GenerateBlocks Query Loop on Archive Pages

Home Forums Support [Resolved] Filter GenerateBlocks Query Loop on Archive Pages

Home Forums Support Filter GenerateBlocks Query Loop on Archive Pages

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #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!

    #2537331
    Ying
    Staff
    Customer Support

    Hi 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');
    #2537378
    Manzelov

    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?

    #2537387
    Ying
    Staff
    Customer Support

    In 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.

    #2537388
    Manzelov

    Thank you!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.