January 24, 2012, 11:45 am 0 Replies

Get All Post ID’s in WordPress, get_all_post_ids()

So, there is a get_all_page_ids() function that returns all the page ID’s, but there isn’t a get_all_post_ids(). So, I built one! *Working in WordPress 3.3.1

function get_all_post_ids(){
	global $wpdb, $post;
	$postids = $wpdb->get_col($wpdb->prepare("
	    SELECT id
	    FROM $wpdb->posts
	    where post_type = 'post'
	    AND post_status = 'publish'
	"));
	return $postids;
}