Guys please someone help me.
49 mins before bumping? 🙁 bad style
this forum has a page that highlights unanswered posts. By impatiently bumping this, youve moved this thread off that page.
a little advice for next time, try to be patient and dont bump
add this to your plugin somewhere
function wp_exist_post($id) {
global $wpdb;
return $wpdb->get_row(“SELECT * FROM wp_posts WHERE id = ‘” . $id . “‘”, ‘ARRAY_A’);
}
that bizare that wordpress hasn’t it
The original question asked about finding the post from its title, so here is a version of the above function to find a post by title:
function wp_exist_post_by_title($title_str) {
global $wpdb;
return $wpdb->get_row("SELECT * FROM wp_posts WHERE post_title = '" . $title_str . "'", 'ARRAY_A');
}
Since this was also asked, here is a function that returns an array of all post titles:
function wp_get_all_post_titles() {
global $wpdb;
return $wpdb->get_col("SELECT post_title FROM $wpdb->posts");
}
Thanks for this I am a real newbie on WP.
But I would qualify your query a little so that you only display this conditional data if the page is in fact published.
My example below returns the ID of a page and I am limiting it to child pages of post_parent=17:
function wp_exist_page_by_title($title_str) {
global $wpdb;
return $wpdb->get_row("SELECT ID FROM wp_posts WHERE post_title = '" . $title_str . "' && post_status = 'publish' && post_type = 'page' && post_parent=17", 'ARRAY_N');
}