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.