Custom – show “premium” terms first

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?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 );

{{/gist}}