Using WP Grid Builder with Bricks

I’m hoping someone can help with a couple of quick questions about using WP Grid Builder alongside Bricks. I’m just getting started with both, using in a couple of development projects.

In one project, I have a couple of custom post types (events and learning) that share some taxonomies (tags, categories). Both Bricks and Grid Builder have been huge helps in getting close to a working prototype, but I’ve encountered two issues. I’d welcome any help on these if possible!

  1. Grid output on archive pages
    I’m ‘recycling’ a grid across a number of templates. This has worked well, with the exception of the archive template. For some reason, after activating the ‘Archive Template’ switch, the correct custom post types show, but the grid ignores the sort order. The sort order on the same grid works fine across other pages/templates, but not here. I’m guessing it’s probably something that requires a support ticket to WP Grid Builder, but thought I’d ask in case anyone has any experience with this. (For reference, I’m sorting by a custom post field).

  2. Creating an ‘all category’ view
    This one is perhaps a little trickier, but I’m not sure if I’m just not approaching it sensibly… I want to create a page that shows all categories (including sub-categories), with a few learning/event opportunities for each. Before installing Grid Builder, I’d worked out a way to use the query loop on the page to loop through the relevant taxonomy (the shared category type). Then, within each loop, I can nest a subsequent loop to retrieve the actual content. However, I’m not sure how best to fit Grid Builder in with this approach. How do I pass the necessary category id to Grid Builder, in essence to say “please just show me results relevant to this category”?

Any advice on the two questions would be greatly appreciated!

Thanks,
Andy

Hi

for question 1, archive pages are always a little bit tricky. Have you tried with / without this setting in the Bricks query?

Regarding question 2, there are a few ways to achieve that (if I fully understood what you are trying to do).

One if not the easiest way, is to simply put the filter parameters into the url. You would put the filter parameters into the url in the menu item (or a link on another page), and then when someone clicks on the menu (or a link on another page), then the page url including the filter parameters is loaded.

An example:

I have a page with the url “https://www.example.com/archiv/fotoarchiv/” that has a WPGridbuilder facet with its Facet Slug “jahr_der_galerie”.

To make this facet being active with the filter “2019” when the page is loaded via the menu or a link, I add the following to the url:

https://www.example.com/archiv/fotoarchiv/?_jahr_der_galerie=2019

If you have more than 1 facet that you want to be active, just add the facets like this into the url:

https://www.exmple.com/archiv/fotoarchiv/?_archiv_der_galerie=2019&_archiv_user=59727

Again, I am not sure I fully understand what you are trying to do. If not, there are a few PHP filters that you can use with WPGridbuilder, for example

function prefix_facet_settings( $settings )

or

function prefix_filter_query

Cheers and good luck

Patric

Many thanks for your reply, @Patric – much appreciated.

Regarding question 1, the support team of WP Grid Builder responded super-fast to this question and clarified that, when using the grid in an archive template, WordPress over-rides any query specifics, such as sort order. It is possible to amend this with some PHP via pre_get_posts:
pre_get_posts – Hook | Developer.WordPress.org

Thanks for your response regarding question 2. I’ll dig into this now and see what I can come up with!

Cheers,
Andy

1 Like

Just in case anyone wonders, I got #1 resolved with the following code. This is specific to Modern Events Calendar, but should be adaptable enough should anyone need to lift it (I’m certainly not a PHP nor a WordPress expert, so caution is advised!!) This fixes the sort order on category archive pages. The meta_query element resolves the fact that, otherwise, category archives view will include old/past events which isn’t ideal. This filters those out.

function ubs_mec_order( $query ) {
    if ( is_archive() && !is_admin() && $query->is_main_query() ) {
        $query->set( 'meta_key', 'mec_start_date' );
        $query->set( 'orderby', 'meta_value' );
        $query->set( 'order', 'ASC' );
		$query->set( 'meta_query', array(
            array(
                'key'     => 'mec_start_date',
                'compare' => '>=',
                'value'   => date('Y-m-d'),
                'type'    => 'DATE',
            )
		));
    }
} 

add_action( 'pre_get_posts', 'ubs_mec_order' );
1 Like