Last active
January 31, 2020 20:02
-
-
Save mgibbs189/f969864780d6609e8b0b018a59a5b1a7 to your computer and use it in GitHub Desktop.
Custom - show "premium" terms first
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Grab the premium posts and _intersect_ them at the beginning of the final ID array | |
*/ | |
add_filter( 'facetwp_filtered_post_ids', function( $post_ids, $class ) { | |
$premium_query_args = array( | |
'fields' => 'ids', | |
'facetwp' => false, | |
'post_type' => array('photographer', 'videographer'), | |
'post_status' => 'publish', | |
'orderby' => 'rand', | |
'posts_per_page' => -1, | |
'tax_query' => array( | |
'relation' => 'OR', | |
array( | |
'taxonomy' => 'photographer-category', | |
'fields' => 'slug', | |
'terms' => 'premium-member-photographer', | |
), | |
array( | |
'taxonomy' => 'videographers_category', | |
'fields' => 'slug', | |
'terms' => 'premium-member-videographer', | |
), | |
) | |
); | |
$premium_query = new WP_Query( $premium_query_args ); | |
$premium_ids = $premium_query->posts; | |
// narrow premium IDs to those contained within $post_ids | |
$premium_ids = array_values( array_intersect( $premium_ids, $post_ids ) ); | |
if ( ! empty( $premium_ids ) ) { | |
$temp_post_ids = $post_ids; | |
$post_ids = $premium_ids; | |
foreach ( $temp_post_ids as $id ) { | |
$post_ids[] = $id; | |
} | |
} | |
return $post_ids; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment