Site logo

Archived topic

Elements header overridden by "sort by date" feature in WooCommerce (FacetWP)

5 replies · Started by Lars Steen on November 3, 2018

Viewing posts 1–6 of 6

Hello GP.

I'm working with GPP plugin and using:

FacetWP
Woocommerce GPP
Elements GPP

For sorting use I FacetWP, that takes over the query to achieve the desired sorting.
Somehow when sorting by "date" the Elements header gets overridden and return the first header created.

F.x: http://localhost/m/shop/?orderby=date

In path .../m/wp-content/plugins/gp-premium/elements/class-conditions.php (from line 241)
Inside:

public static function show_data( $conditionals, $exclude, $roles ) {
    // I var dump
    var_dump($conditionals);
    // ...
}

I get the first created header element (date):
array(1) { [0]=> array(2) { ["rule"]=> string(18) "general:front_page" ["object"]=> string(1) "0" } }
This overrides the settings inside the Elements element the is set for "Shop front page"

I expect to see the selected header element:
array(1) { [0]=> array(2) { ["rule"]=> string(9) "post:page" ["object"]=> string(2) "85" } }

I guess it's because the Elements module also gets sorted by "date"

My guess is that there are also other plugins that add "sort by date" or alike to the query.
(This could be something)

I'm looking at this:
$posts = get_posts( $args );
from line 34 in /htdocs/m/wp-content/plugins/gp-premium/elements/elements.php

My idea is to make a "new" query here and then reset query after.
I dont even know if this would work, and i dont want to hardcode stuff in the plugin.
Also i need to ensure, that it will "play nice" with WPML.

Do you have any idea of how to overcome this?

Best regards. Lars.

Hi there,

I wonder if FacetWP gives you an option to ignore a custom post type via a filter? That way we could just tell it to ignore Elements.

Might be worth asking them :)

Thank you for fast response :)

This is just sharing experience for others:

FacetWP code says in comment it should ignore get_post();
$is_main_query = ( true === $query->get( 'suppress_filters', false ) ) ? false : $is_main_query; // skip get_posts()

I also tried what Tom suggested (thanks Tom)
https://facetwp.com/facetwp-debugging/ - "FacetWP is using the wrong query"

add_filter( 'facetwp_is_main_query', 'testaaaa', 10, 2 );
function testaaaa( $is_main_query, $query ) {
    //if ( 'product' == $query->get( 'post_type' ) ) {
    if ( 'gp_elements' == $query->get( 'post_type' ) ) {
        $is_main_query = false;
    }
    return $is_main_query;
}

$is_main_query = false; on gp_elements had no effect.
If I change the ifclause for posttype product, then it sets the main query with false, FacetWP dies but the header shows as expected.

I will contact FacetWP tomorrow, to see if they can help :)

Hmm, well gp_elements definitely wouldn't be the main query on the page. Let me know what they say :)

Hello Tom.

It was an issue in facetWP, they pushed an update for me and it works now.
Thanks for your time and fast response.

It a pleasure to be a GP user :)

Best regards. Lars.

Great to hear! Thanks! :)

This archived topic is closed to new replies.