If Membership 2 is active FacetWP won't work

I'm having a problem with the membership plugin, it's causing another plugin FacetWP to not work.
FacetWP basically lets you add some checkboxes to search pages to filter down your search results https://facetwp.com
It appears to use ajax to retrieve information on which checkboxes it should show and which are selected
It's this ajax request that I think is breaking.
It works with Membership disable and stops working as soon as turn membership on again.

Link to WPFacet zip file included in chat.

  • Predrag Dubajic
    • Support

    Hi Jon,

    I was doing some testing of this and I can see the issue on your site but it looks like it happens only while you're logged out, with admin account the filtering on Bookmarks page works fine.

    However when I test this on my installation I couldn't replicate this issue.

    Could you give it a try with default WP theme and only M2 and Facets plugins active, without any Facet add-on plugins and see it it works for you in that case?

    This should help us with pointing the issue so we can debug it further from there.

    Best regards,

  • Dimitris
    • Support Star

    Hey there Jon,

    hope you're doing good today and don't mind chiming in here! :slight_smile:

    As the support access period has been expired, could you please re-grant it for us and let us know here in your next reply?

    Would it be fine to further test this by enabling/disabling plugins and themes in this staging environment? Please advise!

    Warm regards,

    • Paul Kevin
      • Neo

      Hello Jon ,

      Hope you are well today. I managed to see the category list when not logged in, but the list does not show when logged in there are no categories shown. On checking the Ajax response in both cases, I noticed for logged in FacetWp will not return the categories in the ajax request. I suspect there is a hook in FacetWP that is not running well when retrieving the categories. Part of the response when logged in is {"facets":{"categories":"","tags":""}} as compared for a logged out user where there is a HTML output for the categories and the tags.
      Further digging into the code I noticed FacetWP relies on a global variable to hold the query variable and results. This could be cleared or lost when a user is logged in since Membership also carries out post and category query filters. I have not found any hooks to get passed this, you may have to talk to the plugin developer at FacetWP for further insight on the issue. I am happy to give more feedback on this. Hope this helps

      Warm Regards
      Paul Kevin

  • Ivan
    • Developer

    Hi Jon !

    If you still bump into this conflict - you can try to fix this issue. Please, open {wordpress_folder}/wp-content/plugins/facetwp/includes/class-ajax.php file via FTP and change this line (approximately 111th line)
    $is_main_query = ( $query->is_archive || $query->is_search || ( $query->is_main_query() && ! $query->is_singular ) );

    $is_main_query = $query->is_main_query() && ! $query->is_singular;

    Also, you can notify author of this plugin about this issue.
    Note: we don't recommend to change code of any plugins because you lost all changes after updating them but in this case, there is not another way.

    Best regards,

  • Sebastien
    • New Recruit

    If anybody else is also stuck with this.
    Not yet perfect but this could be a better solution than playing in FacetWP code.
    Solve the problem for me.

    // Add to your (child) theme's functions.php
    add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
        if ( 'ms_relationship' == $query->get( 'post_type' ) ) {
            $is_main_query = false;
        return $is_main_query;
    }, 10, 2 );

    Found there: https://gist.github.com/mgibbs189/d097d6a0ae06f316a3212c3c4c20eee5

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.