- This topic has 4 replies, 2 voices, and was last updated 4 years, 8 months ago by
Jason.
-
AuthorPosts
-
-
May 21, 2017 at 11:43 am #8243
friendlyfire3MemberHello, you uncommonly beautiful piklist team!
I was referencing this post: https://piklist.com/support/topic/post-relationship-and-the-wp-rest-api/
and noticed that the post_has and post_belongs filters have stopped working on the latest version of wp api and the beta version of piklist (0.10).
1st, I’ve made sure the CPT object called “places” with the ID of 1234 has posts related to it.
Then I tried:
/wp-json/wp/v2/posts?suppress_filters=0?post_has=1235and even thought I know it doesn’t use the filter[] structure anymore, I tried
/wp-json/wp/v2/posts?filter[suppress_filters]=0&filter[post_has]=1235Neither of these work. I also made sure the query vars were added with:
add_filter('rest_query_vars', function($valid_vars) { return in_array('post_has', $valid_vars) ? $valid_vars : array_merge($valid_vars, array('post_has', 'post_belongs')); });Any idea what I’m missing?
-
May 21, 2017 at 12:08 pm #8244
friendlyfire3Memberfyi, I’ve tried post_has and post_belongs. All of them just return all the posts for the endpoint type.
-
May 24, 2017 at 7:09 pm #8261
JasonKeymasterHey @friendlyfire3!
We do feel pretty uncommonly beautiful. Thanks for noticing! 😀
So the WP API changed some very key parts when merging into core. I’m afraid I haven’t had time to fix it. The way that it used to work was to use post_has, post_belongs, or relate_query in the filter parameter of the request. But the filter query parameter support was removed when the API was merged into core. So now a different method is needed.
I’m going to throw together a branch in Github to try and tackle this, which I invite you to test. Otherwise, you’re welcome to install the Filter plugin and use the old method.
I’ll post here again once I have the branch and pull request for this made.
Cheers! 🙂
-
May 24, 2017 at 11:22 pm #8262
friendlyfire3MemberAwesome, Jason. What’s the branch name? I’ll definitely pull it and test for you.
-
May 25, 2017 at 12:46 pm #8263
JasonKeymasterJust made a pull request for it! Check it out! https://github.com/piklist/piklist/pull/31
-
-
AuthorPosts
- You must be logged in to reply to this topic.