我在wp-json上有500个错误。
如果我尝试echo get_rest_url(),就会得到example.com/wp-json,这会给我带来错误500。我将RewriteCond %{REQUEST_URI} !^/wp-json添加到我的.htaccess中,这给我带来了404错误。
我使用postname作为permalinks的设置。我也尝试过http://example.com/?rest_route=/wp-json/v2/posts,它给了我错误500。
编辑:好的,我打开了wp_debug。现在我得到了错误:Fatal error: Call to undefined function register_rest_route() in /customers/0/2/1/。这是我的新错误。有线索吗?
发布于 2020-06-24 15:20:45
您是否试图使用该功能而不首先在操作中启动它?应该这样做:
add_action( 'rest_api_init', 'add_custom_users_api');
function add_custom_users_api()
{
register_rest_route( 'route', array(
'methods' => 'GET',
'callback' => 'function',
));
}发布于 2018-07-18 03:42:04
创建一个.htaccess文件
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPresshttps://wordpress.stackexchange.com/questions/301030
复制相似问题