FacetWP Query Detection with Pro - Feedback from FWP

Hi,

The Facets on my site stopped working, after quite a bit of investigation it came down to FWP not detecting the query string from the Looper Provider. Using a filter I fixed it but there’s no clue why this broke after 7 months in production.

This is the query in question:

post_type=plant&facetwp=true&order=ASC&orderby=title&meta_query[0][key]=hps_image_type&meta_query[0][value]=Conservation Plant&meta_query[0][compare]==&meta_query[relation]=AND

This includes the &facetwp=true which is supposed to be picked up by FWP, but failed.

The feedback from FWP is below, which might make more sense to you:

The one you posted earlier used $query->query_vars instead of $query->get which for some reason seems to be more reliable to match against.

With strict query detection on - facet only detects a main archive query, a custom query with facetwp=>true, or a facetwp listing template. With strict query detection off, any query that wordpress identifies as an archive query can be detected even if its not the main query but this often causes unwanted auto-detection.

Without seeing what is happening in code with the page builder, it is hard to access by the facetwp=>true isn’t working but there are a number of page builders I have seen that only work by using facetwp_is_main_query to target the correct query.

@charlie Maybe this is useful for future Pro query strings?

Best wishes, Bill.

I’m not entirely sure what the response means. I would guess a WordPress update might have broken your production since we haven’t touched the query string setting of the looper provider. Posting what filter you used to fix this might also help me.

The file that houses the custom looper provider for queries is here. This might help them.
cornerstone/includes/_classes/dynamic-content/class-looper-provider-user-query.php

Here’s the filter, simple really:

function custom_facetwp_is_main_query($is_main_query, $query) {
// Array of post types that should be recognized as main queries
$allowed_post_types = array('plant', 'hps-event', 'photographs');

// Check if the query's post type is in the allowed list
if (isset($query->query_vars['post_type']) && in_array($query->query_vars['post_type'], $allowed_post_types)) {
    return true;
}

return false;
}
add_filter('facetwp_is_main_query', 'custom_facetwp_is_main_query', 10, 2);

When I looked in the JS console, the query being picked up was the regular ‘posts’ query, this is on a regular page not an archive. The filter rejects anything other than the three CPTs I have filtering for.

I might pass on the file above, but I’ll take a look first and see.

Thanks, Bill.

Hi Bill,

Thanks for sharing the information. Keep us in the loop as you play around with the code above.

Cheers.

Also keep me in the loop, I would love to see a proper facetwp integration. @bill_hodgson I would appreciate some insights of how to managed to get it to work.

@reunel it would be great if there was some official documentation. I’ve seen you recommend factwp a number of times, but theres no clear info on how to implement it.

Hey @kylehill,

The FacetWP is not officially supported by our theme but we have observed some users successfully implementing it for filtering options. Consequently, we have not provided official documentation for it. For a list of plugins supported by our theme, please refer to the following resource.

Hope that helps.

@kylehill

FWP is easy to use with Pro.

  1. Buy and install FWP on your site
  2. Add some facets, that is an index for some data in your site
  3. Grab the shortcodes for the filters and insert into raw elements at relevant places on your page or archive
  4. If your page has a provider, using a query string, add &facetwp=true to the query
  5. Also add facetwp-template as a class to whatever container is outside of your looper consumer

See how you get on. Here’s an example of what can be done: https://hardy-plant.org.uk/plants-and-seeds/

Or jump into the Facebook forum for Pro and ask there. https://www.facebook.com/groups/ThemecoUsers

Bill.

Hey Bill,

Thanks for sharing your idea, we really appreciate your time and effort.

Cheers!

I’ve run into the same issue where FacetWP was working perfectly one day and then was failing to detect the query string the next.

After doing some testing something seems to have changed in the 4.3.1 update below of FacetWP to cause the issue. As reverting to the previous version fixes the query detection.

  • ImprovedStyling for “locked” (i.e. code-based) facets and templates
  • ImprovedListing builder - hide the “Reset” facet mobile header
  • ImprovedCheckboxes - the “See more/less” links are translatable
  • FixedQuery detection should ignore queries running inside get_the_excerpt (i.e. some block-based templates)
  • FixedACF - prevent deprecated notices for NULL date values
  • FixedFWP.active_facet not working in some browsers

With the new version Facets still work in archive templates but trying to implement them in a page builder with custom query string seems to be a no go without the filter you’ve added above Bill.

Hey @yoorrookthemeco ,

Thanks for sharing your idea, we really appreciate your time and effort.

Cheers!

Appreciate your help with this Bill. Have joined the facebook group.

Just to clarify, we only need to set up filters? Or do we set up a listing too?

Not sure what you mean by a listing.

But yes, I solved this with the code snippet above which only allows specific post types to be filtered using FWP

I mean in facetwp, you can create a filter and then a listing for that filter. Did you create any listings or just use the filter directly with Pro loopers?

Hey @kylehill,

You will use the FacetWP filters. It should work with the Looper.

Thanks.

@kylehill

Here’s my Facets: https://share.cleanshot.com/XJd7YWsc

They index the underlying data and produce the widgets you insert into the page.

Here’s my page with the FacetWP widgets highlighted : https://share.cleanshot.com/PlqJ1hlr

And here’s how you embed an FWP widget into the page: https://share.cleanshot.com/F0xWmLw3

I used a text field but I’m sure a raw field would work too.

If you begin using FWP, the whole point is to use their widgets and their indexing to achieve dynamic filters on your page. Josh did a video a while back showing the use of a dropdown to create a customer URL e.g. www.website.com/?category=plant and then using Pro to extract the URL segment to filter the page. But that means reloading the entire page, whereas FWP uses Ajax and refreshes the data on the page without reloading.

There’s two scenarios with FWP:

  1. On an archive page, where the query has already run, no Looper Provider
  2. On a regular page where you write the Provider

For case 2, you can modify the query string to help with detection, in case 1 you may need the custom code and filter above.

I hope this all helps, Bill.

Hey @bill_hodgson,

Thanks for your explanation. @kylehill hope you are able to make your filter work.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.