Viewing 4 reply threads
  • Author
    Posts
    • #8243

      Hello, 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=1235

      and 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]=1235

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

    • #8244

      fyi, I’ve tried post_has and post_belongs. All of them just return all the posts for the endpoint type.

    • #8261
      Jason
      Keymaster

      Hey @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! 🙂

    • #8262

      Awesome, Jason. What’s the branch name? I’ll definitely pull it and test for you.

    • #8263
      Jason
      Keymaster

      Just made a pull request for it! Check it out! https://github.com/piklist/piklist/pull/31

Viewing 4 reply threads
  • You must be logged in to reply to this topic.