0

I'm aware that get_page_by_title() is not an option when you want to look for posts (or CPTs in my case) that are not published (i.e. in draft).

Some of the solutions that I've found are based on SQL queries, but they are old examples (more than 5 years old), and I'm afraid that they are not recommended according to the best practices on SQL queries using the wpdb class.

So... how to get it?

Maybe there's a filter or hook for the get_by_page_title() function? Perhaps the best way to achieve it is writing a custom SQL query? And how? What do you think?

0

You could try this:

$args = array("post_type" => "mytype", "s" => $title, 'post_status => array('draft'));
$posts = get_posts( $args );
  • Thanks @am_ but this is searching on title and content... I want to search only inside the title – Capiedge Apr 16 '18 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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