You should use the pagename
parameter for WP_Query along with post_parent
. Limit your query to one post using posts_per_page
.
$parent_id = get_the_ID();
$args = array(
'post_type' => 'page'
'pagename' => 'page-2',
'post_parent' => $parent_id,
'posts_per_page' => 1
);
$posts = get_posts( $args );
$child = isset( $posts[0] ) ? $posts[0] : false;
if( $child ){
//Do Something
}
This, in theory, should render your desired post by slug using the parent ID.
Related Posts:
- What query string parameter is available for index.php, that works for both pages and blog articles?
- how to get page id of a page using page slug
- the_date() not working
- The correct method to pass query vars in AJAX using ajaxurl
- wpdb::prepare was called incorrectly
- How to order WP_User_Query results to match the order of an array of user IDs?
- Alter query on edit.php
- How to find objects by terms
- How to create a WP_Query to search the Title or Tag?
- How to get user by display_name with WP_User_Query
- my function doesn’t return my post from today
- Put a link to a category round a hard coded A HREF
- Display related products with custom output
- spliting posts into two columns
- WordPress – query 5 posts with a specific post in top
- Multiple choice in a custom taxonomy
- Rename “Portfolio” slug?
- How to get a list of all possible values of a specific user meta key?
- How to query for pages/post depending on slug?
- Get stock by custom meta field on all Woocommerce variable products
- Any possible way to make $wpdb->get_results() return anything else than array?
- WordPress custom slug (endpoint) and compare all links
- Global variable $post returning incorrect object
- How do you use WP slugs for PDF files / media?
- Accessing the database from a plugin outside of action hooks
- Echo a hierarchical list of post data from custom fields
- WP Query with custom Shortcode
- Storing Array from returned database query and using the array in a new query
- mysql query from wordpress page using custom table
- WordPress 3.2 query_posts and pagination, permalinks issue
- only show container with next/prev links if they exist?
- What is an equivalent of single_cat_title for getting the slug of the category?
- php script to change slug in post automatically
- Long running queries
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- How to pre populate a form field with a link of a current user’s author profile?
- Query if audio attachment AND/OR custom field
- register_taxonomy() take much queries
- Odd / Even posts add class minus first post
- unable to use ‘new WP_Query’ in AJAX call
- Parse error: syntax error, unexpected ‘}’ on get_the_author_meta [closed]
- How to add div blocks after certain set of post
- working with term_relationships table
- WordPress query undefined offset in loop
- Can I make get_users() query global?
- page-slug.php not working but only for specific slug
- Issue with custom loop in Archive page
- Parse error: syntax error, unexpected ‘}’ [closed]
- PHP -> SQL Query with Summing
- How to hide posts of a specific custom category in WordPress?
- Remove slugs from custom posts type
- WordPress PHP syntax doesn’t seem to be working correctly
- How to get thumbnail with pure PHP in a WordPress database?
- Getting the slug into a variable, how to echo that variable
- mySQL queries are executed twice on wordpress website
- Echo array value
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Display latest post from WordPress Featured Category that is also in X,Y,or Z categories
- Query pulling a single post per month
- WordPress Custom Query: Combining Two Functions
- SQL error with custom query
- WordPress Conditional / Multiple Taxonomy Query
- How can I modify this code to make the search box include tags and meta
- Reject all malicious URL requests functions.php
- Advanced Query posts
- How can I check that the acf field value is not a duplicate when adding a post?
- My Custom Post Type AJAX Query is Returning no posts – why?
- Get nice name of category from slug (remove dashes of category)
- array wordpress when get is null
- Custom PHP form needs refresh to load page correctly
- Why does a header location on admin_head remove the query var I’m setting in the location?
- getting the values of hidden inputs to use them in a php mysql query
- Offset with ajax load more posts duplicates
- Let user select the number of posts shown per page jquery error
- Query doesn’t display text data with apostrophes
- How to query a staging database?
- How to make a parent page for author.php?
- How can I output the slug of a comment author?
- Include a custom field in mysql query
- WordPress using get_term to retreive slug not working as expected
- Echo multiple tasks if a common function exists
- Weird slug in archives permalink
- How to enqueue assets only on queried pages, excluding the page being queried?
- php string inside shortcode does not work
- Check if values exists DB
- Trying to exclude posts from a category on the home page
- Arrange Category post manually when displayed
- get_category only returning details for ‘uncategorized’
- The search engine of my website finds only posts and not pages, how can I solve this problem?
- category & sub category order issues in wordpress
- Hide empty categories from get_categories
- Query Concatenation
- How to insert a variable into a query parameter?
- wp_query on search results page showing all results every time
- WP_Query not returning results
- Sorting a custom post type in pre_get_posts
- How to disable page create for custom post type, but allow a page with the post types slug to be created?
- SQL query to retrieve the number of WordPress posts with all given categories
- Create a custom plugin with dynamic child pages listing database records
- Custom Filtering date with newsletter