Scenario
I'm considering writing a custom wp-json endpoint to list ALL permalinks for everyone post in my wordpress.
Question
Is it possible to do this with a rest query + filters? eg. http://wpsite.com/wp-json/wp/v2/posts?filter[only-permalinks]
Current Solution
I ended up writing a custom endpoint, code below:
added to the bottom of functions.php
function get_all_slugs() {
$posts = get_posts( array(
'numberposts' => -1,
'post_type' => "screen",
) );
if ( empty( $posts ) ) {
return null;
}
$posts_data = array();
foreach( $posts as $post ) {
$id = $post->ID;
$posts_data[] = (object) array(
'id' => $id,
'slug' => $post->post_name,
//'title' => $post->post_title,
);
}
return $posts_data;
}
add_action( 'rest_api_init', function () {
register_rest_route( 'row/v1', '/all-slugs', array( // /(?P<post_type>\d+)', array(
'methods' => 'GET',
'callback' => 'get_all_slugs',
) );
} );