I use this maybe helpfull
<?php
$title = get_the_title($post);
$parent_title = get_the_title($post->post_parent);
echo $title;
echo $parent_title;
?>
<?php
global $post; //wordpress post global object
if($post->post_type == 'page'){
$content .= '<br /> This item is a page and the ID is: '.$post->ID;
} elseif($post->post_type == 'post') {
$content .= '<br /> This item is a post and the ID is: '.$post->ID;
}
echo $content;
?>
Related Posts:
- Page template query with WP_Query
- How to display page content in a page template?
- Does WordPress generate an automatic page for post formats?
- Single page theme that uses pages for the content
- Trying to list out child pages with WP_Query
- Order by menu structure
- Targeting specific pages in the loop
- What are the differences between “Latest Posts” and “Static Page”?
- WP_Query not retrieving by random order under parent
- Set if condition with wp_nav_menu
- Set order of returned items in the WP_Query() class/function
- Search pages that are a child of the current page
- How to display summary content from a Page (Not a Post) on another page
- Serve specific “template” page at any URL that ends in its slug
- Display custom tags on pages that have a specific page parent
- Is there a reason why Pages are not publicly_queryable?
- Why post__not_in is ignored?
- Exclude parent with child pages from WP_Query
- Create a loop on my pages with new “WP_Query”
- All blog data on a page using custom query gives 404 for page 2 and onward
- When listing child pages run out of memory
- WPQuery calling specific posts problem
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- Display specific page (that is child) content on parent page
- Get query results with a page title
- How to get current page nearest parent id?
- How to get main menu only with wp_nav_menu
- Unable to paginate a custom page query
- How to create single page site in WordPress
- Determine if ID is page or post and query the ID
- How to query for a page, get data, then query for child pages of that page
- Get list of all Grandchild Pages
- Custom query does not find pages
- How to get pages of parent (non-recursive)?
- WP Query and multiple pages
- How to use custom page for all posts with custom url, call another directory?
- display the children of the post using the current page as the main parent
- pages shortcode filtering by category
- How to create page that lists tags by initial letter?
- Get a page ancestor from a most viewed list
- How can I use a specific wordpress page template if certain words are used in page title [closed]
- Category Archive not working for pages
- Retrieving category pages from subcategory returns empty sets
- Issue in If else condition [closed]
- Show parent’s child and also child’s, child on a page?
- get contents and permalink from a specified page
- Hierarchical List Pages as a table
- Get next post when using pagination with WP_Query?
- WordPress pagination returns the same posts
- Rewrite URL custom search query
- Paginate_Links page 2 doesn’t work
- When should you use WP_Query vs query_posts() vs get_posts()?
- WP_Query by just the id?
- How to get post id of static front page?
- Get post ids from WP_Query?
- How to query for most viewed posts and show top 5
- Delete all posts from WordPress except latest X posts
- WP_Query result in form of Rest API results
- get_posts with multiple categories
- WP Query to get all posts (including in draft/pending review)
- Overriding The Loop with filter or hook
- Slow SQL_CALC_FOUND_ROWS Query
- Perform query with meta_value date
- Custom archive page based on array of categories and tags
- How can I connect to another WP database and use WP_Query?
- Compare two meta-fields in a wp_query (where meta-field-A is larger than meta-field-B)
- Different Results with query(‘s=computer’) vs get_posts(‘s=computer’)?
- Why does “Blog pages show at most” interfere with my custom wp_query?
- Recommended way to drop a pending query (in pre_get_posts)?
- How to search for posts IN OR title OR content OR author?
- Search – Ajax – Alter Query Parameters with Pagination
- Access to Instance Variables from WP_Query
- WP Query with multiple categories – passing an array works?
- Custom query, works, but I get a “Notice: Undefined offset: 0…”
- SQL User Query by Multiple Roles using PHP
- how to speed up a complex wp_query?
- How to capture a variable query string, then append it to all URLs in a WordPress site
- How to display future posts – modified query still yields 404
- Exhausted memory limit with very simple WP_Query
- WP_Query do not load specifed number of post
- WP_Query doesn’t get sticky post at the top, when used in a page template
- What’s faster? One big query, or several smaller ones?
- Meta Query for specific months
- Sort users by “birthday” using WP_User_Query
- Overwriting posts_per_page in new WP_Query
- How to use WP_Query without breaking the main Query
- Trouble with wp_reset_postdata() in Admin Panel
- Wp_query returning only one post while query through ajax
- only delete post within query / for each statement (front end)
- Database Queries Optimization with new WP_Query
- query_vars filter not working even though query string parameter is present
- How to optimize multiple WP_Query() calls on one page?
- How to make “Blog pages show at most” setting not affect custom queries
- Bypass “supress_filters” in WP Query
- meta_query BETWEEN, but the range is stored in the custom field
- date_query on draft posts only
- Having trouble with WooCommerce Storefront child theme single.php “related posts” modification [closed]
- Order ascending is ignored in meta query?
- Custom Pagination in Shortcode with WP_Query
- WP Query – Post Thumbnail