Can i check if a post with the title "great title" exists even if this post status is set to "draft" with the function: post_exists("great title") ?

1 Answer 1


Yes, as post_exists("great title") runs the following SQL:

SELECT ID FROM $wpdb->posts WHERE 1=1 AND post_title = 'great title'

so there's no post status or post type restriction.

Check the docs on post_exists() for more info.

If you want to restrict by post type, you can use:

$found_page = get_page_by_title( "great title", $output = OBJECT, $post_type = 'page' );

See the docs here.

  • Thanks, i was actually looking at the docs and they don't seem to mention it (can you point me?). for some reason it doesn't seem to work for me, but now i will know to look for another reason...
    – mondi
    Jul 25, 2017 at 17:40
  • You're welcome. I just looked at the code there :-)
    – birgire
    Jul 25, 2017 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.