Вопрос

i am using WP rest API v1 and everything is ok.

But now i want taste some WP rest API v2. the problem is, when i cal:

mysite.com/wp-json/wp/v2/posts

or:

mysite.com/wp-json/wp/v2/post

or

mysite.com/wp-json/wp/v2/posts/

or any thing else is related ti this path:

mysite.com/wp-json/wp/v2...

the result is:

[{"code":"json_no_route","message":"\u0647\u06cc\u0686 \u0645\u0633\u06cc\u0631 \u062a\u0637\u0628\u06cc\u0642 URL \u0648 \u0631\u0648\u0634 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u067e\u06cc\u062f\u0627 \u0634\u062f"}]

and i don't know what is the problem and the point is i want to use WP rest API v1 and v2, together, so disabling WP rest API v1 is not an option.

PS: I removed and add WP rest API v2 but nothing change.

Это было полезно?

Решение

OK, i find my answer. Just ask it here and as dear Charles sayed, they answered me, so fast, the answer is:

By default, WP-API v1 takes priority over v2. If v1 is installed and activated, then v2 routes are inaccessible.

To mitigate this, you'll need to register either v1 or v2 to a different base than wp-json. Both have filters to make this more or less easily possible:

add_filter( 'rest_url_prefix', function() {
    return 'wp-api';
});

and because i am not a WordPress guy, so i don't know where should i add this lines so i get help from this blog and add the lines to the

function.php

of my them.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с wordpress.stackexchange
scroll top