-
Notifications
You must be signed in to change notification settings - Fork 153
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
Added ability to view all post types when Pulling from an External Connection #1002
base: develop
Are you sure you want to change the base?
Conversation
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.
Thanks for the PR @mehul0810
I've left couple non-blocking questions and a suggestion for the $args
in get_pull_content()
return; | ||
} | ||
foreach ( $remote_get_args['post_type'] as $type ) { | ||
$remote_get_args['post_type'] = $type; |
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.
Not sure if rewriting the source array index 'post_type'
(on which we perform the foreach block) with the scalar value is a good option.
While technically it works fine and the code block will execute as expected, this assignment modifies the $remote_get_args['post_type']
from the array to the last element only.
$remote_get = $connection_now->remote_get( $remote_get_args ); | ||
|
||
if ( is_wp_error( $remote_get ) ) { | ||
$this->pull_error = $remote_get->get_error_messages(); |
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.
After converting the routine from single to multiple remote requests, this $this->pull_error
only assigned with the most recent request errors instead of combining errors from all requests.
$args = [ | ||
'posts_per_page' => isset( $request['posts_per_page'] ) ? $request['posts_per_page'] : 20, | ||
'paged' => isset( $request['page'] ) ? $request['page'] : 1, | ||
'post_type' => isset( $request['post_type'] ) ? $request['post_type'] : 'post', | ||
'post_type' => array( 'post', 'page' ), |
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.
Shouldn't we use the $post_type
variable described a few lines above?
'post_type' => array( 'post', 'page' ), | |
'post_type' => $post_type, |
@@ -437,10 +437,13 @@ function check_post_types_permissions() { | |||
* @return \WP_REST_Response|\WP_Error | |||
*/ | |||
function get_pull_content( $request ) { | |||
$post_type = isset( $request['post_type'] ) ? $request['post_type'] : 'all'; | |||
$post_type = 'all' === $post_type ? array( 'post', 'page' ) : $post_type; |
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.
@mehul0810 I think we should not accept all
as the value of post_type
. We should be specific about which post_type posts we should return in the result. We can update the rest API post_type
param to accept string
and array
to query more than one post type simultaneously.
Let me know if you have any questions.
In #1017 (awaiting merge) I've made a bunch of modifications to the rest api endpoint that should make this more achievable. It will probably cause a lot of conflicts to this PR though. You'll be able to use |
@mehul0810 thanks for the PR! Could you please rebase your PR on top of the latest changes in the base branch? |
Description of the Change
Closes #861
How to test the Change
Changelog Entry
Credits
Props @username, @username2, ...
Checklist: