You can use get_page_by_title()
or get_page_by_path()
.
By default, both return a page’s WP_Post
object, from which you can extract data. If the page doesn’t exist, they’ll return null
.
You can also use them on post types other than the built-in page
.
// By slug.
$slug = 'sample-page';
$page_by_slug = get_page_by_path( $slug );
// By title.
$title="Sample Page";
$page_by_title = get_page_by_title( $title );
Related Posts:
- Disable Attachment Pages Completely
- Print number of post (in reverse)
- Best practice for migration friendly images in posts/pages?
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Parsing Menu Items and Blog Posts
- Automatically add images to a menu
- WordPress Search
- Edit and delete permissions pages and posts
- My worpress search page is showing no results
- Split post or page content in two or more columns
- Getting page / post URL on publish and / or update
- Get current_post in reverse order with pagination
- List of child pages fetch next results at link click
- How to show part of the_content?
- Page Automatically Generated from Theme?
- How to add a php custom page to WordPress
- Sort query_posts for Parent Pages to menue order or the count?
- How to hide all child pages with post_query?
- Unreadable pagination
- 200 Rewrite blog post links
- How to set a min number of words for a blog post
- Loop through categories and display posts title under each dropdown
- Get post id in a function when edit/add a post
- how do I get a specific post from a post with a subcategory in WP
- Automatically create child pages and grandchild pages when saving a (parent) page
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Second transition_post_status hook fired instead of the first
- How to store post ID’s in cookie or session to display the same posts later
- Which hook/action will help me solve my problem?
- How can I add extra word in permalink when someone click download button?
- My page.php shows the index.php
- Post + form + action + results on the same page
- Open post-content in archive page in a Modal box with bootstrap
- Populate editor with some content of a page with a page template
- How can I add an area/option for a custom page description?
- Create Page To Count Comments For Each Post In WordPress Site
- remove post that has no content
- Loading index.php contents which located outside blog folder for post single page
- get post content of particular post by url
- Post repeating with infinite scroll
- Custom posts in different columns style
- Get children post mime type using parent post_ID wp_post
- How to show only subcategories in parent category not parent category?
- 404 error when I acess the second page of post-type
- get_the_title() gets printed out twice
- How do I find PHP file that contains content of my page?
- WordPress page content outside WordPress
- Using the_excerpt() on a page
- Inject class in body when particular page template is used
- Which PHP page is the Default Posts Page
- Use .php file as page instead of wordpress page & template file?
- Use WordPress function in php file
- retrieve post data and insert it in seperate static html page without WordPress
- WP Insert Post and then go to post
- Returning data instead of echoing/printing
- Display related posts without a plugin
- How to check if the current page is at a specified path in the URL?
- Counting Search results, and displaying the offset per page
- Count posts on multisite with blog id
- Function works everywhere, how to keep it to execute when creating a new post
- Making (and edit existing) posts with ID included
- Copy taxonomy terms from one post to another programmatically
- Show About and Contact Us page when they’re clicked in the top menu.
- Pagination on Custom Post
- How to use theme function in post/page?
- $wpdb returns duplicate posts
- How to avoid duplicates when creating recent network posts
- How to show an entire post content and not also the excerpt?
- Get latest post from all categories except one
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- My php code is not being executed
- Update post title from external file?
- Parse error: syntax error, unexpected end of file
- trouble with page_id & highlighting current page
- Apply class to every third list item? [duplicate]
- How to include custom code on a page that’s set to act as homepage?
- Can a page contain php code?
- What’s the best way to include PHP code in pages?
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Load Posts on Click via Ajax into a DIV
- How to catch wordpress post ID when it’s published
- set post limit at load more ajax wordpress
- WordPress query undefined offset in loop
- Find Site ID From WP_Post
- WP_Query: getting posts where custom field exists
- page-slug.php not working but only for specific slug
- Need php code’s output to display underneath a Divi Module
- Insert page content into another page with a changed variable
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Only show first image in foreach loop
- How to echo every parent page title?
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- How to use mysql LIKE with wpdb?
- Reading settings in the home page precisely home.php
- Do I need to edit my theme in order to change the title of my blog page?
- Add new post in existing categories using wp_insert_post
- WordPress upload file size error even after raising php limits
- How do I add more options to the post-new.php page?