Skip to content
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

Fix post_parent returning early if set to 0 #3211

Merged
merged 12 commits into from
Dec 19, 2022
Merged

Fix post_parent returning early if set to 0 #3211

merged 12 commits into from
Dec 19, 2022

Conversation

felipeelia
Copy link
Member

This is a simple takeover of #3196

Description of the Change

This change changes empty( $args['post_parent'] ) to ! isset( $args['post_parent'] ) so any query or pre_get_posts (or similar) filter that sets post_parent to 0 will still work as expected.

Closes #3181

How to test the Change

As seen in #3181, use a filter like the following on a hierarchical CPT to confirm the confirm child posts are actually removed.

add_action( 'pre_get_posts', function( $query ) {
	if ( is_admin() ) {
		return;
	}

	if ( ! $query->is_main_query() ) {
		return;
	}

	if ( ! $query->is_post_type_archive( 'things' ) ) {
		return;
	}

	$query->set( 'post_parent', 0 );
});

Changelog Entry

Fixed - Queries with post_parent set to 0 not working correctly

Credits

Props @JiveDig

Checklist:

  • I agree to follow this project's Code of Conduct.
  • [] I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@felipeelia felipeelia added this to the 4.4.1 milestone Dec 16, 2022
@felipeelia felipeelia self-assigned this Dec 16, 2022
@felipeelia felipeelia merged commit 2bd6774 into develop Dec 19, 2022
@felipeelia felipeelia deleted the fix-3181 branch December 19, 2022 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pre_get_posts to only show top level CPT is not working while ep_integrate is true
2 participants