There is a function exactly for that:
get_page_by_title( $page_title, $output = OBJECT, $post_type="page" );
You can use it like this:
$page = get_page_by_title( 'Start' );
To get the page from a specific post type:
$custom = get_page_by_title( 'Start', OBJECT, 'your_custom_post_type' );
$post = get_page_by_title( 'Start', OBJECT, 'post' );
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:
$status = get_post_status( $page );
if ( 'publish' !== $status )
return; // do not show unpublished posts
A related function is get_page_by_path()
:
$page = get_page_by_path( 'about/contact' );
Related Posts:
- How to get current page ID outside the loop?
- How to get page title with the page ID?
- What is an alternative to get_page_by_title()?
- Cannot get grandparent object
- Making audio playlist by getting page’s parent’s ID
- How to get page_id for url rewrite or how to use page slug for calling a page?
- Is it possible to restrict access to specific pages in the admin area based on the page slug?
- List child pages within page template
- How to get an array of pages ID by some page’s slug and all its children pages in get_posts() function?
- Get ID of the page where shortcode is included
- get id custom tables on current page
- Get page id by template
- How can I keep the content of my pages version controlled?
- How to load JS and CSS only on specific Pages using is_page()?
- Listing pages which uses specific template [duplicate]
- How do I convert a page’s title to lower case?
- page title, parent tilte and grand parent title
- How to add jQuery script to an individual page?
- WordPress page edit does not save selected template
- Increment Page Order As Pages Are Created
- Is there a way to remove or hide individual pages on the Edit Pages screen?
- Add custom admin menu item for pages using a certain template
- Where does the 404 redirection happen?
- How to limit page pagination
- Display latest comments on page with pagination
- How to add pages to feed?
- Add custom text at bottom of every page?
- Creating custom page
- Want Page Title to show on menu, but not on page
- How to create a metabox that will list all my pages in a dropdown selector?
- Personal page for every user (not just authors)
- Create ghost page
- Relative instead of absolute links in pages?
- Produce a plain page with only a message
- load common thank you template with different content for different pages
- Password Protected Page Title
- Send mail from page using wp_mail
- Edit page’s “Restore the backup” link does nothing
- Show preview posts and pages to clients
- Page displays content from different query?
- Site url is not showing the home page
- Can’t locate a hidden private page
- I can’t edit my homepage – the page editor is just blank [closed]
- Restricting Pages based on Hierarchy and User Role
- page-name.php doesn’t execute on custom template
- How to retrieve attachments from child pages of a specific Page?
- how to display sidebar on pages in wordpress
- Hide page templates without using ‘unset’
- Custom page with queries returns 404
- page.php is not called, falls back to index.php
- Custom page in archive page for certain category
- I would like my page editor to be sorted by date created, or updated, instead of in Alpha order, is this possible?
- Is it possible to check for shortcodes on a page?
- WordPress 3.2 – removed ability to select a page template in the page attributes when adding a new page?
- Show FormCraft form on page open [closed]
- Use same page-mypage.php template for several pages
- Why last blog post excerpt is shown instead of meta description? [closed]
- Prevent non-admin to add/create new pages
- How do you implement a page template automatically being applied to a page?
- Make “default” wordpress pages & features unaccessible
- Set a variable to using in redirected page
- Show parent & child pages with featured image and hide the current page
- Publish page by invoking submit via jQuery
- One author not showing in Author drop down list while editing page
- WordPress Page Protect forwards to Admin Login
- How can I edit pages from my local environment?
- Modifying .page-content background image
- Displaying the blog entries in a Page (using get_posts to retrieve the posts)?
- “Can’t update in WordPress”
- Why can’t pages be categorized / tagged?
- Adding in additional pages into a custom theme
- Pages in wp-admin is not found 404
- Shortcode runs when editing page
- List of pages of a specific user
- WordPress dosn’t save page/post updates
- Multiple meta_key with get_pages
- Sup pages can’t be found
- How to use wp_dropdown_pages or wp_list_pages to accomplish a menu like this?
- Get child pages in get_pages function
- Send e-mail from admin area to adresses in custom field
- Bundle a page with custom url and a function
- Custom Upload Adds Ghost File
- How to exclude sidebar from pages?
- Widget & storing a Select box choice
- How to Change the path of a child page?
- Annoying notification when trying to create a new page
- Page stuttering on load
- disable trashability for certain pages
- how bbPress and buddypress add their own page templates to the page template drop down on the page editing screen
- If searched in a category show different 404 page
- Using array page name together with page id to deregister script
- pages won’t show on front page using loop or pre_get_posts
- How can I cycle posts with a #next and #previous script?
- Using Page/Post Slug In Link / URL
- get_pages gives wrong ID for blogpage
- List of pages – AJAX load more
- one time visit to the page
- How to display text of a page in home or custom page?
- How do I count the number of pages a user has seen on my site, and force them to log in after a certain amount
- Fresh WordPress installation not able to simply show page content