Looking for some help with a repeater using an advanced query using ACF.
I've got two custom post types: Product, Vendor
Vendor has a sponsored field. Product has a relationship field connected to Vendor
I am trying to sort the Product Archive loop by the sponsored field, so that Vendors that are sponsored have their products show at the top of the list.
I can't for the life of me figure out who that query should be written. It's been like 3 hours of attempting everything to no avail!
This is the code I'm starting with:
function solution_directory( $query ) {
if ( $query->is_main_query() && !$query->is_feed() && !is_admin() && $query->is_post_type_archive( 'solution' ) ) {
$meta_query = array(
array(
'key' => 'sponsored',
'value' => 'yes',
'compare' => 'IN'
)
);
$query->set( 'meta_query', $meta_query );
$query->set( 'orderby', 'meta_value' );
$query->set( 'meta_key', 'sponsored' );
$query->set( 'order', 'ASC' );
$query->set( 'posts_per_page', '4' );
$query->set( 'facetwp', 'true' );
}
}
add_action( 'pre_get_posts', 'solution_directory' );
The real answer is this can't be done. So instead, I opted to switch up my workflow and create the sponsored
field within the Solution
custom fields so I could query it directly.