I’m using a WP_Query to query my custom post type posts. This custom post type has parent and children pages. I’m trying to pull the first parent page. How would I do this?
Leave a Reply
You must be logged in to post a comment.
I’m using a WP_Query to query my custom post type posts. This custom post type has parent and children pages. I’m trying to pull the first parent page. How would I do this?
You must be logged in to post a comment.
You can achieve this functionality by making a query to database;
Note:-
$wpdb
is global variable.Once you have run your query and you are looping through it, you can access the ID of the parent of each post with
$post->post_parent
, and if that is not null you can get that post content withget_post()
: