I'm using the rest_photo_query
filter to manipulate the arguments of WP_Query
through the use of my own GET
parameters. It's working perfectly and fast, with one exception.
I can adjust the orderby
parameter using rest_sht_photo_collection_params
, and it's easy to sort the results by meta_value
.
The photo Custom Post Type entries are connected to a second Custom Post Type species by means of the species_id
.
I need to be able to sort the photo posts by species title.
Does anyone have a good idea how to achieve this? As I'm modifying the WP_Query
in a standard endpoint, my preference would be to modify the WP_Query
arguments somehow.
I've tried building my own query in a custom endpoint and then modifying the resultant array by looping through it, but this makes the request about 100x slower.
Here's a partial example of a simpler field, where the custom orderby my_custom_meta_field
is added as a meta_value
comparison:
switch ($args['orderby']) {
case 'my_custom_meta_field':
$args['orderby'] = 'meta_value';
$args['meta_key'] = 'my_custom_meta_field';
break;
WP_Query
can do, and adding levels of indirectness is not something you want to dometa_query
in there too). Otherwise the pagination doesn't work. We're talking about nearly 10,000 posts, so I can't send them all to the frontend and let the browser handle the filtering and sorting.species
then fetch posts for each species in order and using the species totals count to figure out pagination? The posts first approach is going to be extremely expensive. You're going to want to invest in a lot of caching at multiple levels to make it work at any kind of scale ( think more than a handful of concurrent users/requests )