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
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...– mondiJul 25, 2017 at 17:40
-