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

Only public post types will be selectable in the autocomplete Redirect To field #332

Merged
merged 1 commit into from Jun 30, 2023

Conversation

bmarshall511
Copy link
Contributor

Description of the Change

Autocomplete will now only display public post types.

Closes #331

How to test the Change

  1. Go to add a new redirect page (/wp-admin/post-new.php?post_type=redirect_rule)
  2. Start typing in the "Redirect To" field
  3. Only public post types should be displayed

Changelog Entry

Fixed - Only public post types will be selectable in the autocomplete Redirect To field

Credits

Props @bmarshall511

Checklist:

@bmarshall511 bmarshall511 requested a review from a team as a code owner June 30, 2023 16:21
@bmarshall511 bmarshall511 self-assigned this Jun 30, 2023
@bmarshall511 bmarshall511 requested review from iamdharmesh and removed request for a team June 30, 2023 16:21
@ravinderk ravinderk merged commit 046dc24 into develop Jun 30, 2023
11 checks passed
@ravinderk ravinderk deleted the fix/331-ben branch June 30, 2023 16:23
'post_type' => get_post_types(),
'post_type' => get_post_types(
array(
'public' => true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I know this has already been merged in but I think the better approach here is to use the is_post_type_viewable function to filter the post types (see 10up/distributor@4b8b77e and 10up/distributor#907 (comment)).

So something like:

'post_type' => array_filter( get_post_types(), 'is_post_type_viewable' )

This checks for both the public argument and the publicly_queryable argument

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing query:
image

@dkotter I am getting the following result with the above code.
I think redirect_rule should not display in the list.

What do you think?

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, doesn't make sense to show redirect rules within the redirect field. We can either unset that post type (see again Distributor: https://github.com/10up/distributor/pull/907/files#diff-a4c20b6d7391a224faf11e6161c80b408e2a0f5a71a92dc11b7eafe3cad83f94R320) or utilize the is_post_type_viewable core filter to remove the redirect_rule post type from showing (which would impact anyone else using this function, may or may not be a good thing)

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.

Show publicly available post types in autocomplete dropdown for Redirect To
4 participants