Skip to content

Commit

Permalink
Merge pull request #1944 from CityOfPhiladelphia/blog-endpoints
Browse files Browse the repository at this point in the history
add filtering by template for posts endpoint
  • Loading branch information
m-atia committed Jul 20, 2023
2 parents fbab878 + edfe038 commit e438d60
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
add_filter( 'rest_post_query', 'filter_post_by_archived', 10, 2 );
add_filter( 'rest_post_query', 'filter_post_by_featured', 10, 2 );
add_filter( 'rest_post_query', 'filter_post_by_language', 10, 2 );
add_filter( 'rest_post_query', 'filter_post_by_template', 10, 2 );


function get_phila_template( $post ) {
Expand Down Expand Up @@ -102,5 +103,24 @@ function filter_post_by_language( $args, $request ) {
),
);

return $args;
}

//add filter for template
function filter_post_by_template($args, $request) {
$template = $request->get_param( 'template' );

if ( empty( $template )) {
return $args;
}

$args['meta_query'] = array(
array(
'key' => 'phila_template_select',
'value' => $template,
'compare' => '=',
),
);

return $args;
}

0 comments on commit e438d60

Please sign in to comment.