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

Improve get_page_by_title() query WHERE clause #3562

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

dilipbheda
Copy link

Trac ticket: https://core.trac.wordpress.org/ticket/56991


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@10upsimon
Copy link

@dilipbheda Any chance we can get the change log notes added to the function doc block as part of this fix?

@dilipbheda
Copy link
Author

@10upsimon added in the latest commit.

@10upsimon
Copy link

@10upsimon added in the latest commit.

Thank you @dilipbheda

@mukeshpanchal27
Copy link
Member

Thanks @dilipbheda for the PR. can you please show SQL query after the changes? how can this be tested in Unit test?

@dilipbheda
Copy link
Author

@mukeshpanchal27 Sure!, I've exclude the trash, auto-draft post status from the query.

SELECT 
  wp_posts.ID 
FROM 
  wp_posts 
WHERE 
  1 = 1 
  AND wp_posts.post_title = 'Test' 
  AND wp_posts.post_type = 'page' 
  AND (
    (
      wp_posts.post_status = 'publish' 
      OR wp_posts.post_status = 'future' 
      OR wp_posts.post_status = 'draft' 
      OR wp_posts.post_status = 'pending' 
      OR wp_posts.post_status = 'inherit' 
      OR wp_posts.post_status = 'request-pending' 
      OR wp_posts.post_status = 'request-confirmed' 
      OR wp_posts.post_status = 'request-failed' 
      OR wp_posts.post_status = 'request-completed' 
      OR wp_posts.post_status = 'private'
    )
  ) 
ORDER BY 
  wp_posts.post_date ASC, 
  wp_posts.ID ASC 
LIMIT 
  0, 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants