How to use?
i have installed this plugin, how to using this plugin, i try like this http://mysite/wp-json/wp/v2/posts?filter[slug]=hello-world, and not working. thanks
With "jQuery + Promises" i use the plugin something like this:
getContent: function(tags, category) {
console.log('getContent: ', tags.join(","));
var deferred = new $.Deferred();
$.ajax({
url: '/wp-json/wp/v2/posts',
method: 'GET',
data: {
'filter[tag]': tags.join(","),
'filter[category_name]': category
},
success: function(data, status, xhr) {
deferred.resolve(data);
}
}).fail(function(jqXHR, textStatus) {
console.log("getContent | Request failed: ", jqXHR, textStatus);
});
return deferred;
},
Where:
- tags is an array
- category is an string
@radhitee If you are looking to search by slug, you do not need to use this plugin: You can make the request
http://mysite/wp-json/wp/v2/posts?slug=hello-world
and you should get what you want.
@kadamwhite That method did not work for me. My post also has a category specified, is it necessary that it is passed in the query? If I have a post with slug named "hello-world" with category of "learning-center" how would I retrieve that post?
@produktive If the slug is "hello-world", then the code I posted should work; for example http://demo.wp-api.org/wp-json/wp/v2/posts?slug=this-is-a-test correctly returns a collection with only the post with the slug "this-is-a-test" on the API demo site. You're on WordPress 4.7.2?
With ?filter you may be able to use filter[name]=hello-world, but the ?slug approach is the recommended one. The category should not be relevant. Could you paste the full API URL (omitting the domain name for privacy) that you're trying, so we can see if there's something else going on? What results do you get back for the ?slug=hello-world query?
@kadamwhite I will paste the full URL so you can see for yourself that something strange is going on. Check out this page: https://www.healthfitcorpwell.com/wp-json/wp/v2/posts/1432 You can see the slug is "what-sitting-on-your-wallet-does-to-your-back" Nothing returns if you try to call it by slug: https://www.healthfitcorpwell.com/wp-json/wp/v2/posts?slug=what-sitting-on-your-wallet-does-to-your-back Any ideas?
@produktive I tested it and it shows fine
@DeLonge I discovered it was a plugin compatibility issue with Paid Memberships Pro which they just resolved a couple days ago. In fact, it wasn't even resolved yet. You need to install a second plugin called PMPro REST API which was just patched a few days ago to resolve the issue.