I’m using the following code to insert the content from another wp page into my main home page.
Is it possible to make it work with a page title instead of an id number?
Eg. Not $page_id = 518 but $page_id = ‘about’ instead????
$page_id = 518; //Your Page ID
$page_data = get_page( $page_id );
// Displays the title
echo '<h1>'. $page_data->post_title .'</h1>';
// Displays the content
echo apply_filters('the_content', $page_data->post_content);
?>
There is a function exactly for that:
You can use it like this:
To get the page from a specific post type:
Be aware, this function will search in all post statuses. So you might get a draft, a trashed or private post. You should check the result with:
A related function is
get_page_by_path()
: