Problem with custom WordPress Rest API search route with query parameters

It isn’t reading the acceptable image type parameter because there is no code to read it, and the acceptable image types have been hardcoded here:

            array(
                'key' => 'accepted_image_type',
                'value' => array('print', 'glass-plate'),
                'compare' => 'IN',
            ),

Much like you did here for the search parameter:

$search_query = $data['s'];

It needs to do the same for the acceptable image type parameter too.

Sidenotes:

  • Post meta is ultra fast when you already know the post, get_post_meta is blazingly fast for this reason because you have to give it a post ID. But, post meta is awful for searches, and the performance/scaling cost rises dramatically as the size of the post meta table increases. Instead either replace this field with a custom taxonomy, or store it in both so that you can get the performance benefits of replacing it with a tax_query
  • you can probably replace this endpoint with the default stock endpoints that come with WordPress. The URLs might not be as pretty due to the extra URL parameters but it would eliminate a bunch of code to maintain for free