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

How to use? #10

Open
radhitee opened this issue Feb 3, 2017 · 7 comments
Open

How to use? #10

radhitee opened this issue Feb 3, 2017 · 7 comments

Comments

@radhitee
Copy link

radhitee commented Feb 3, 2017

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

@ghost
Copy link

ghost commented Feb 3, 2017

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

@kadamwhite
Copy link
Contributor

@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.

@produktive
Copy link

@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?

@kadamwhite
Copy link
Contributor

@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?

@produktive
Copy link

@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?

@DeLonge
Copy link

DeLonge commented May 16, 2017

@produktive I tested it and it shows fine

@produktive
Copy link

produktive commented May 16, 2017

@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.

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

4 participants