I am using rest_{post_type}_query
for some custom query params. It works fine, however, I would like to get an empty response or a "no posts found" message when the query doesn't have the posts ids to match. Currently it gets all the posts.
function query_video_by_politician($args, $request) {
if(isset($request["politician_id"]) && intval($request["politician_id"])) {
$mp_entry_ids = FrmEntryMeta::getEntryIds( array(
'fi.form_id' => 41,
'meta_value' => intval($request["politician_id"]),
'field_id' => 517
) );
$mla_entry_ids = FrmEntryMeta::getEntryIds( array(
'fi.form_id' => 41,
'meta_value' => intval($request["politician_id"]),
'field_id' => 518
) );
if ( !empty($mp_entry_ids) ) {
$entry_ids = $mp_entry_ids;
}
if ( !empty($mla_entry_ids) ) {
$entry_ids = $mla_entry_ids;
}
if ( !empty($entry_ids) ) {
$where = array(
'form_id' => 41,
'id' => $entry_ids
);
$post_ids = FrmDb::get_results( 'frm_items', $where, 'id, post_id' );
if ( $post_ids ) {
foreach( $post_ids as $post ) {
if( !in_array( $post->post_id, $post_ids ) )
$ids[] = $post->post_id;
}
$args['post__in'] = $ids;
}
}
}
return $args;
}
add_filter('rest_gallery_query', 'query_video_by_politician', 10, 2);