You remember the post How to get a page/post content, don’t you? Then, we may get the page/post content by:
function getPageBySlug( $slug )
{
$objectPost = get_page_by_path($slug);
return apply_filters("the_content",$objectPost->post_content);
}
As you can see from the code above, we used get_page_by_path()
function instead get_page_by_title()
function, because some plugin ( like qTranslate ) could change the content on the database. In fact, the get_page_by_title()
function gets a content of a page through a database SELECT statement:
function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) {
global $wpdb;
$page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts
WHERE post_title = %s AND post_type= %s", $page_title, $post_type ) );
if ( $page )
return get_page($page, $output);
return null;
}
So, if for some reason the title has been changed then the get_page_by_title()
function doesn’t work properly. The get_page_by_path()
function uses the slug. Further, the get_page_by_path()
function works with private pages as well.