Gists

4 months ago
<?php
/** filter main query using while specifiying the page
 ** with FWP()->helper->get_uri()
 ** use page without domain and /'s, ex. 'somepage/mypage'
 **/

add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
    if ( 'news' == FWP()->helper->get_uri() && 'my_cpt' == $query->get( 'post_type' ) ) {
        $is_main_query = false;
    }
    return $is_main_query;

}, 10, 2 );
6 months ago
<?php

add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
    if ( 0 === strpos( FWP()->helper->get_uri(), 'author' ) ) {
        $is_main_query = false;
    }
    return $is_main_query;
}, 10, 2 );
10 months ago
<?php

add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
    return $query->is_search() ? false : $is_main_query;
}, 10, 2 );
12 months ago
<?php

/** give your query an id of "use_facet" **/

add_action( 'elementor/query/use_facet', function( $query ) {
	$query->set( 'facetwp', true );
} );

add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
	if ( true !== $query->get( 'facetwp', false ) ) {
		return false;
	}
	return $is_main_query;

}, 10, 2 );
12 months ago
<?php

/** for an on sale product query add this to query args, use in advanced query view
 ** for layout templates - ex. https://d.pr/i/p5hxWm
 ** "post__in" => array_merge( [0], wc_get_product_ids_on_sale() )
 **/

/** this may cause facet to detect the query used in wc_get_product_ids_on_sale
 ** use this filter to prevent
 **/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
    if ( 0 > $query->get( 'posts_per_page', 0 ) ) { // skips in query for -1 as post_per_page
        $is_main_query = false;
    }
    return $is_main_query;
}, 10, 2 );
1 year ago
<?php

add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
    if ( 'elementor_library' == $query->get( 'post_type' ) ) {
        $is_main_query = false;
    }
    return $is_main_query;
}, 10, 2 );
1 year ago
<?php

add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
	if ( $query->is_search() && $query->is_main_query() ) {
		$is_main_query = false;
	}

	return $is_main_query;
}, 5, 2 );
2 years ago
<?php

// Add to your (child) theme's functions.php
// woocommerce_rest_{$this->post_type}_object_query

add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
    if ( false !== strpos( $_SERVER['REQUEST_URI'], 'wp-json/wc/v3' ) ) {
        $is_main_query = false;
    }
    return $is_main_query;
}, 10, 2 );

/*
add_filter( 'woocommerce_rest_product_object_query', function( $args ) {
    $args['facetwp'] = false;
    return $args;
});
*/
6 months ago
<?php
/** only detects queries that are set to facetwp=true explicitly **/
 
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
	if ( true !== $query->get( 'facetwp', false ) ) {
		return false;
	}
	return $is_main_query;
}, 10, 2 );
2 years ago
<?php
/** make sure facet always targets the archive query as the main query
 ** sometimes there is a mysterious extra query that is a duplicate 
 ** of the main query
 **/
add_filter( 'pre_get_posts', function( $query ) {
    if ( $query->is_archive() && $query->is_main_query() ) {
        $query->set( 'facetwp', true );
    }
}, 9 );
 
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
    if (  $query->is_archive() && true !== $query->get( 'facetwp' ) ) {
        $is_main_query = false;
    }
    return $is_main_query;
}, 10, 2 );