try this.
global $post; // if outside the loop
$page_object = get_queried_object();
$page_id = get_queried_object_id(); // Get current page id
$args = array(
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'hierarchical' => 1,
'exclude' => '',
'include' => $page_id,
'meta_key' => '',
'meta_value' => '',
'authors' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
$parentID = $pages[0]->post_parent; // Get current page parent id
This will gives you current page parent id, not top-level id $parentID = $pages[0]->post_parent;
Related Posts:
- Order by menu structure
- Set if condition with wp_nav_menu
- How to get main menu only with wp_nav_menu
- Show parent’s child and also child’s, child on a page?
- Meta_query compare operator explanation
- Nested meta_query with multiple relation keys
- Page template query with WP_Query
- meta_query ‘compare’ => ‘IN’ not working
- How to display page content in a page template?
- Sorting: custom query with orderby meta_value_num THEN by title
- WP_Query with checkbox meta_query
- ACF Relationship Field Search Filtering [closed]
- Query Multiple Post types each with own meta query
- Does WordPress generate an automatic page for post formats?
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- Meta Query with date and time on the same Day before given time
- How to grab metabox value in wp_query meta_query key
- Is “orderby” in WP Meta Query conflicting with Meta Query?
- How can I create a WP_Query that returns posts where one meta_value
- WP Meta Query for some meta (array) values
- Sort users by meta_value_num
- meta_query with array as value
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Generate a tabbed submenu — from taxonomy term or submenu item — with sample content
- Using WP Query to search within ALL keys in meta query
- WP Query – Get WooCommerce Products with variation that is in stock
- Meta_query with or without value
- Warnings in nav-menu when visiting query pages [closed]
- Undefined property: WP_Query::$post
- wp_query not searching with apostrophe
- Extending woocommerce admin product search
- Set order of returned items in the WP_Query() class/function
- Add condition of user capability in WP_query
- Custom query based on meta key – Reduce three states to two in results?
- How to make Meta Query case sensitive?
- Performance when getting post meta for post retrieved by meta value
- Any number in meta key (wp query)
- How to display multiple custom fields with the same meta_key in an ascending order?
- Meta_query with multiple keys and multiple values
- Is it a good idea to improve meta query performance by adding tax query?
- Modify wp-query and sort by post meta key
- Tax query AND/OR meta query [duplicate]
- Orderby listing issue
- Help ordering Post loop by two meta values
- Why post__not_in is ignored?
- Make meta query treat meta_value as 1 or 0
- Is this meta query problematic?
- WP Query Meta Value – How To Identify Specific, Unique Values?
- Order by meta_key doesn’t work
- Appending to existing WP_Query’s meta_query if exists
- Multiple meta_key ordering with pre_get_posts
- Get meta_value of a specific meta_key from all posts belonging to a specific custom type
- Custom query filter by ACF date custom field
- Query by date from custom field
- Nested array issue in meta_query
- Error in meta_query not get result
- Meta query with compare by more than 2 fields
- Unable to paginate a custom page query
- meta_query with array as value with multiple arrays
- How to create single page site in WordPress
- Why doesn’t my WP Meta Query return any results?
- Determine if ID is page or post and query the ID
- Sort posts using multiple custom fields and menu_order in single query?
- meta_query where the meta value is not the post title
- Order (by ASC) posts with meta_key so posts without values are last
- Search filter between promo and exact price
- meta_query – check for multiple meta values in key which holds an array of values
- build child and anchestor three from post parent
- WordPress Meta Query Null Values Order
- show most viewed post
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- Why can my filter query SOME metadata but not other metadata?
- Getting posts by custom field value
- WP_Query on custom key and value
- Get posts having meta value between two numbers
- wordpress multiple meta value query is not working
- Strange results from WP_Query
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- Pre get posts sort by meta key returns no results if meta key does not exist
- Sorting with meta_query and multiple, optional meta keys
- meta_query with relation = AND not working as expected when combining EQUALS with NOT EQUALS
- WP Query for Multiple Post Types
- Query by meta value (add a dropdown of all values)
- Order Posts By Custom Field That is an array of objects
- Orderby query does not work for custom fields even with meta query
- make query more simplest and in one query
- WP_Query returns empty if meta_query has more than 7 values
- Use not custom fields in get_posts() meta_query?
- Compare meta key separation
- WordPress meta_query not working
- Using orderby with 2 meta keys
- Passing conditional arrays to WP_Query() [closed]
- WordPress Query Default Order if Meta Values Same?
- Custom query (author is post_author or meta co_author) with Pagenavi pagination
- Wp query by 2 meta field – check if they exists / have value
- Get all user with both meta_value
- How to get all post_id and meta_value using meta_key in wp_postmeta table
- WP Query – Show custom posts only if user contain some user meta
- How do I subquery with custom meta fields?
- Showing Counts on Comment List with Custom Query