How to get FacetWP working with Oxygen Builder’s Easy Posts component

Share on linkedin
Share on facebook
Share on twitter
Share on reddit
Share on email

This is a short “how-to” for those of you looking to add FacetWP support to your Oxygen Builder “Easy Posts” components.

Table of Contents

Overview

FacetWP lets you add advanced filters to your WordPress site. This is especially useful if you have shop archives, recipes, listings, and more.

Unfortunately Oxygen Builder and FacetWP don’t fully support each other yet (as of June 2021), so I’ve come up with a work-around in order to use the Easy Posts component with FacetWP.

Firstly – as Oxygen doesn’t use themes – we’ll need somewhere to place the code snippets. Oxygen suggests creating a small utility plugin.

Issues

  1. The Easy Posts Oxygen Builder component doesn’t support FacetWP queries.
  2. FacetWP isn’t able to detect the correct query to process.

Solution

1. We need to create a manual query for the Easy Posts component and include a parameter to enable support for FacetWP.

  • With the Oxygen editor open, select the Easy Posts component and navigate to the Primary > Query tab.
  • Select WP Query “manual” and click on the Query Params field.
  • Input your query parameters followed by &facetwp=true

2. FacetWP isn’t able to detect the custom query, so we need to tell it to ignore Oxygen’s ct_template post type.

  • Add the following code snippet to your plugin.
<?php

add_filter('facetwp_is_main_query', function($is_main_query, $query) {
    if ($query->get('post_type') === 'ct_template') {
        $is_main_query = false;
    }

    return $is_main_query;
}, 10, 2);

Once you’ve saved everything the Facets should then load correctly.

Hopefully, we’ll see an official plugin from FacetWP to provide for support for Oxygen Builder soon. They are both great plugins, a big thank you to both development teams.