Posts tagged ‘SQL’

Method to get data of a single wordpress post

function get_post_content($id) {
	global $wpdb;
	$query =
		" SELECT ID, post_title, post_excerpt, post_content, post_content_filtered "
		."FROM $wpdb->posts "
		."WHERE ID = '$id'";
	$pages = $wpdb->get_results($query);
	if( ! empty($pages) && isset($pages[0]) ) {
		//echo( 'Title: '.$pages[0]->post_title."\n" );
		//echo( 'ID: '.$pages[0]->ID."\n" );
		return $pages[0]->post_content;
	}
	return '';
}

note that this method does not distinguish between posts that have or have not been published, this allows the content of an unpublished post to be used eleswhere.

  • Categories

  • Need Code Written?

  • Need a Coding Job?

  • Tags

  • Archives