Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register_rest_route (Custom Route) #47

Closed
yogevlahyani opened this issue Aug 23, 2017 · 0 comments
Closed

register_rest_route (Custom Route) #47

yogevlahyani opened this issue Aug 23, 2017 · 0 comments

Comments

@yogevlahyani
Copy link

yogevlahyani commented Aug 23, 2017

Hello, I've been trying to make a basic auth for a custom route that I made but couldn't find how to do so.

Here's my code:

function AllPostsByDESCDate( $data ) {
$posts = get_posts(array(
'posts_per_page' => 10,
'paged' => $data['paged'],
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => array( 'post', 'page', 'custom-post-type' ), // custom post types
'post_status' => 'publish',
'suppress_filters' => true
));

if ( empty( $posts ) ) {
return null;
}

return $posts;
}

I can send a get http request without Basic Auth while sending an http request to wp-prefix/v2/posts requires me to Basic Auth.

register_rest_route( 'wp-prefix/v2', '/AllPostsByDESCDate/(?P[a-zA-Z0-9-]+)', array(
'methods' => 'GET',
'callback' => 'AllPostsByDESCDate'
) );

I'm using REST API TOOLBOX (https://he.wordpress.org/plugins/rest-api-toolbox/) to choose which endpoint requires an auth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant