1 year 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 ( 'my_page' == FWP()->helper->get_uri() && 'my_cpt' == $query->get( 'post_type' ) ) {
$is_main_query = true;
}
return $is_main_query;
}, 10, 2 );
2 years 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
// Temporary fix for products not appearing on the default product search results page (the page with /?s=searchterm&post_type=product in the URL).
// The issue happens when using FacetWP, SearchWP, and the SearchWP WooCommerce Integration add-on together.
// Also see: https://facetwp.com/help-center/using-facetwp-with/searchwp/#fix-searchwp-and-woocomerce-integration-on-the-default-search-page
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( $is_main_query && $query->is_main_query() && $query->is_search() ) {
if ( true == $query->get( 'wc_query' ) ) {
$query->set( 'using_searchwp', '' );
}
}
return $is_main_query;
}, 11, 2);
11 months ago
// Prevent wrong query detection and empty facets when using the Ultimate GDPR & CCPA plugin
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'ct_ugdpr_service' == $query->get( 'post_type' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
1 year ago
<?php
/**
** skips detecting main query archive query
**/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( $query->is_archive() && $query->is_main_query() ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
/** replace 'fyjhnq' in ln 18 with the element id in your template
** see https://facetwp.com/help-center/using-facetwp-with/bricks/#usage-products-element
** for how to find the element id
**/
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
if ( 'fyjhnq' == $element_id ) {
global $query_offset;
global $query_counter;
$main_query = $GLOBALS['wp_the_query'];
if ( ! isset( $query_offset ) ) {
$query_offset = 1;
if ( 'product_query' == $main_query->get( 'wc_query' ) ) $query_offset++;
}
$query_counter = ( ! isset( $query_counter ) ) ? 0 : $query_counter;
$is_correct_query = ( $query_offset === $query_counter ) ? true : false;
$query_counter++;
$query_vars['facetwp'] = $is_correct_query;
if ( $is_correct_query && ! isset( $settings["query"]["disable_query_merge"] ) ) {
if ( $main_query->is_archive || $main_query->is_search ) {
if ( $main_query->is_category ) {
$query_vars['cat'] = $main_query->get( 'cat' );
}
elseif ( $main_query->is_tag ) {
$query_vars['tag_id'] = $main_query->get( 'tag_id' );
}
elseif ( $main_query->is_tax ) {
$query_vars['taxonomy'] = $main_query->get( 'taxonomy' );
$query_vars['term'] = $main_query->get( 'term' );
}
elseif ( $main_query->is_search ) {
$query_vars['s'] = $main_query->get( 's' );
}
}
}
}
return $query_vars;
}, 10, 3 );
1 year ago
<?php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( $query->is_archive() && ! ( $query->is_main_query() || true === $query->get( 'facetwp', false ) ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 100, 2 );
1 year ago
<?php
/** skip the default archive query **/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( $query->is_main_query() && 'product_query' == $query->get( 'wc_query', false ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
1 year ago
<?php
/** Disables FacetWP's automatic query detection.
** With this code, queries must be explicitly set to enable FacetWP:
** Use a Facetwp Listing Builder listing templates,
** Use a WP_Query with 'facetwp' => true (custom queries or added with pre_get_posts or other filters),
** Use a page builders with an "Enable FacetWP" setting.
**/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( true !== $query->get( 'facetwp', false ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
2 years ago
<?php
/** find the correct query in bricks when it doesn't match the existing rules in the addon
** example is for a query loop in product archive
**/
/** skip the default archive query **/
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( $query->is_main_query() && $query->get( 'wc_query', false ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
/** uses global loop counter to skip occurances of the same query within the
** query loop until we get to the correct one **/
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
if ( 'b872e8' == $element_id ) { // element id https://d.pr/i/77hzdI
global $loop_counter;
$loop_counter = ( empty( $loop_counter ) ) ? 1 : $loop_counter+1;
if ( 2 < $loop_counter ) { // 2 could be changed for other types if needed
$query_vars['facetwp'] = true;
} else {
$query_vars['facetwp'] = false;
}
}
return $query_vars;
}, 11, 3 );
2 years ago
<?php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
$excluded_uris = [ 'shop', 'some_other/page' ];
if ( in_array( FWP()->helper->get_uri(), $excluded_uris ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );