pre_get_posts passes a complete WP_Query object to the filter function. dwls_alter_results just passes an array of posts it gets by calling $wp_query->get_posts().
I don’t know what your dontShowOffs function looks like, so I can’t help you adapt it do work with DWLS. But if it’s calling get_posts() to retrieve an array of posts, that’s what my plugin is already passing to it.
Basically my function reads custom fields to determine if an event status is 1,2 or 3. I only want Live Search to pull those with a status of 1, AND that is later than the current date. Here’s my complete dontShowOffs function:
function dontShowOffs($query) {
global $wpdb;
if ( !is_admin() && $query->is_main_query() ) {
$inactiveevents = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='wpcf-event-status' AND meta_value = 3");
$currentDate = getdate();
$offevents = array();
$pastevents = array();
if ( !is_admin() && $query->is_search() ) {
$offevents = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='wpcf-event-status' AND meta_value = 2");
$pastevents = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='wpcf-start-date' AND meta_value < $currentDate[0]");
}
$soloexcludes = array(38);
$dontinclude = array_merge($inactiveevents, $soloexcludes, $offevents, $pastevents);
$query->set('post__not_in', $dontinclude);
$query->set('orderby', 'type');
$query->set('order', 'DESC' );
}
return $query;
}
If you could help me figure this out if would be greatly appreciated. Thanks!
Hi Dave,
Just following up on this as the issue still remains. Do you have any insights?
Thanks,
Anthony