WordPress REST AP - Filtering json for a custom post type based on relation to another custom post type
My question has to do with filtering a json request for a custom post type that has a relation to another custom post type. I am requesting json data for an ARTIST custom post type - this works beautifully. I can retrieve the Artists and display them on an Agent page without resubmitting the page. Works great. I want to filter that json request so only the ARTIST records where the ARTIST is assigned to a specific AGENT are returned. For example:
Teddy Slatus - Agent Steve Paul - Agent
TimeSlip -Artist managed by Steve Paul Electric Lemurs - Artist managed by Teddy Slatus Whoops Wrong Planet - Artist managed by Steve Paul
When the Agent detail for Steve Paul is displayed, Click a button labeled "manages" and display a list of Steve Paul's Artists right below Steve Paul's detail. I have most of this work complete and it works BUT I can't figure out how to filter my Artist json request so that only Steve Paul's Artists are returned in the json. I do have the relationship custom field set up for Artist --> Agent and Agent --> Artist. I am not seeing anything in the Artist json that I can use to filter by Agent.
I'm going to take my best guess at this without knowing exactly what your json looks like. If you're doing a request for a custom post type "Artist", and the artist's agent is saved in a custom field then I think you can get it with:
$args = array( 'post_type' => 'artist' 'meta_query' => array( array( 'key' => 'agent', 'value' => $agent_name, 'compare' => '=', ) ) ); $query = new WP_Query($args);
And then looping through $query with
while ( $the_query->have_posts() )
Adding REST API Support For Custom Content Types, The REST API can create routes for custom post types and custom Based on example at: https://codex.wordpress.org/Function_Reference/register_post_type for the route wp-json/wp/v2/books instead of wp-json/wp/v2/book/ , which would register_post_type_args filter hook that exists since WordPress version 4.6.0. I was running into this issue as well with my custom post types. You need to query by your custom taxonomy (eg. property_categories, or whatever you named it in your register_taxonomy() function) and then by the term.
If you would like to filter from two different post type than you need to fire two different wp_query and than you can Get the two post types along with their acf meta and use PHP Array Functions ( like Array Interset) to get the common/union or intersection.
Custom post types filtered by taxonomy using REST API v2 , Ok, the solution was: example.com/wp-json/wp/v2/works?work_type=10. It views the work_types as id's. You can view the id's in: Any program is an API. When you have some form of construct in a programming language — like PHP for example — where the construct makes it possible to perform a programming task, that’s a good way to think of an API. Let’s use custom post types as an example. WordPress has a custom post types API.
There is a handy little plugin that has a great track record and is still maintained. Install it, activate it and BAM! all of the custom fields are exposed on the REST API! If you are a WordPress developer simply search plugins for:
ACF to REST API
Thanks to all who contributed ideas to this thread.
Custom post type and metadata support in the REST API , We've recently made some updates to the REST API which is available here on WordPress.com and for any Jetpack-enabled site that has the Notice, that the type is not Group but it is GroupName wich is also another projection that is defined at line 18. line 15 — makes Jackson ignore group field which removes the field from resulting JSON. Spring Data JPA, however, will still recognize it. line 18 — defines another projection that filters Group entity.
Learning WordPress REST API, REST API within later versions of WordPress will provide the possibility of being is JSON, which will allow display in any way, and can even filter the API calls in a to add new content types to it, and another crucial benefit of the JSON API is with the custom post types, which will require a new type parameter to the API Schema # Schema. The schema defines all the fields that exist within a post record. Any response from these endpoints can be expected to contain the fields below unless the `_filter` query parameter is used or the schema field only appears in a specific context.
Filtering categories for custom post type · Issue #24 · WP-API/rest , API call: wp-json/wp/v2/portfolio?filter[category]=”analytics,cloud”. We'll occasionally send you account related emails. This plugin is okay for filtering tags but what if I want to filter categories for custom post type e.g. Check out WordPress REST API Handbook list Posts, see argument categories The WordPress REST API is more than just a set of default routes. It is also a tool for creating custom routes and endpoints. The WordPress front-end provides a default set of URL mappings, but the tools used to create them (e.g. the Rewrites API, as well as the query classes: WP_Query, WP_User, etc) are also available for creating your own URL mappings, or custom queries.
Getting Posts By Taxonomy Or Meta Field With WP API v2.0, wp-json/wp/v2/posts?filter[job-type]=manager BTW, If you're interested in getting custom post types worked with WP-API v2, please refer to Update: For more information, you can download our free ebook, The Ultimate Guide to the WordPress REST API. In my article on the future of WordPress, I wrote about how the introduction of a JSON RESTful API to WordPress core will radically expand WordPress’s reach and capabilities.