I added this snippet of code to my functions.php
to be able to make a request to a custom post type and filter by book_id
add_filter( 'rest_gallery_query', function( $args ) {
$args['meta_query'] = array(
array(
'key' => 'book_id',
'value' => esc_sql( $_GET['book_id'] ),
)
);
return $args;
} );
so with that I am able to make a request to ‘http://localhost:port/wp-json/wp/v2/gallery?book_id=9780061992254’
gallery
is a custom post type and bookd_id
is one of its custom fields
the issue I am having here is after this I can’t do requests to /wp-json/wp/v2/gallery
without book_id
anymmore and I really need to be able to do it, how can I get rid of that situation?
I was looking for a way to make this param optional but I didn’t find anything yet