I have a custom field that I have added to every wordpress post. I created an api endpoint that queries posts where the custom field is a certain value. That works great, the code is:
function fp_acf() {
$args = array(
'meta_key' => 'featured_post',
'meta_value' => 'yes'
);
$the_query = new WP_Query( $args );
return $the_query;
}
add_action('rest_api_init', function() {
register_rest_route('wp/v2', 'featured_posts', array(
'methods' => array('GET', 'POST'),
'callback' => function() {
return fp_acf();
},
));
});
The Problem:
The data that is returned from that endpoint doesn't contain all of the post data that is typically included in, say "/wp/v2/posts", specifically the slug or link.
Question:
I am wondering if it is possible to add the slug of the posts returned in this question query endpoint to the post data being returned?