Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filtra custom_post_type según un par de campos.
<?php
add_filter( 'rest_ajde_events_query', 'event_filter_by_month_and_year', 20, 2 );
/**
* @example http://tudominio.test/wp-json/wp/v2/ajde_events?year=2020&month=3
*/
function event_filter_by_month_and_year($args, $request) {
$year = strval(intval($request['year'], 10));
$month = strval(intval($request['month'], 10));
$args += [
'meta_query' => [
'relation' => 'AND',
[
'key' => 'event_year',
'value' => $year,
'compare' => '='
],
[
'key' => '_event_month',
'value' => $month,
'compare' => '='
]
]
];
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment