-
Notifications
You must be signed in to change notification settings - Fork 2
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
add support for post_types to rest api #59
Conversation
/** | ||
* Add post_type to rest post query if the type param is set. | ||
* | ||
* @param array<array<int, string>|string> $query_args The existing query args. | ||
* @param \WP_REST_Request $request The REST request. | ||
* @return array<array<int, string>|string> | ||
*/ | ||
public function add_type_param( $query_args, $request ): array { // @phpstan-ignore-line | ||
if ( ! empty( $request->get_param( 'type' ) ) && is_string( $request->get_param( 'type' ) ) ) { | ||
$types = explode( ',', $request->get_param( 'type' ) ); | ||
$types = array_filter( $types, 'post_type_exists' ); | ||
$query_args['post_type'] = $types; | ||
} | ||
return $query_args; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get where this is coming from, but I'm concerned that it's not really the correct use of the REST API. It will cause the API to try to apply the schema for the post
post type to posts from any post type, which might have unpredictable results. The search
endpoint is more annoying to use but might be more correct for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks like most of the changes in this PR were rolled back, but approving the small change to post-meta.json.
add support for post_types to rest api and allow
wp_curate_deduplication
on all post types.handles #54 and sort of #56 (could be handled better)