Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Display posts based on custom field › Reply To: Display posts based on custom field
January 31, 2023 at 11:19 am
#41165
Keymaster
Sure, it is possible by adding an additional argument and a tiny modification:
add_filter('asp_results', 'asp_remove_where_no_title_field', 10, 2);
function asp_remove_where_no_title_field($results, $search_id) {
if ( $search_id == 1 ) {
foreach($results as $k=>&$r){
if ( get_post_meta($r->id, 'title_field', true) == '' ) {
unset($results[$k]);
}
}
}
return $results;
}
On line if ( $search_id == ...) change the number to the search ID you want to apply the code to.