Custom Endpoint not working in Multisite
Question
I’m using WordPress sample code for adding custom endpoint to rest api from Add Custom Endpoints in WordPress Rest API Handbook:
function my_awesome_func($data) {
$posts = get_posts( array(
'author' => $data['id'],
) );
if ( empty( $posts ) ) {
return new WP_Error( 'no_author', 'Invalid author', array( 'status' => 404 ) );
}
return $posts[0]->post_title;
}
add_action( 'rest_api_init', function (){
register_rest_route( 'myplugin/v1', '/author/(?P<id>d+)', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'my_awesome_func',
'permission_callback' => '__return_true',
));
});
but it returns rest_no_route (404) in multisite:
http://newsut.ir/wp-json/myplugin/v1/author/1
Same code in another site (not multisite) works correctly:
http://z-design.ir/khelo/wp-json/myplugin/v1/author/1
Multisite .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*.php)$ $1 [L]
RewriteRule . index.php [L]
Options -Indexes
0
2 months
0 Answers
8 views
0
Leave an answer
You must login or register to add a new answer .