I believe your issue is with understanding the nature of posts’ hierarchy vs pages’ hierarchy. A page is a type of “post”. It can have hierarchical structure.
Posts, by default, do not have hierarchy. So, you would not be able to get post-parents without their children, because the system does not recognize a hierarchy. This is true unless you modify the structure with a custom function, or install a specific plugin to add hierarchical structure to Posts.
If you really need that hierarchy, you could try this StackOverflow answer to add a hierarchy. This will permit what you are trying to accomplish.
Related Posts:
- get_the_terms – only top level
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Copy taxonomy terms from one post to another programmatically
- Hierarchical taxonomy list with modificated term links
- WordPress different custom tag being displayed in on tag list
- Show all terms of a custom taxonomy?
- wp_set_object_terms and arrays
- Get used terms by an author as array of strings
- category not display in word press grammatically
- How to get the term before the last from a custom taxonomy?
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- WP_Query use for a filter with multiple Taxonomies and Terms
- New Plugin Review
- Problems with function on function.php
- Use template for posts with a particular category grandparent
- Check if term object is in array
- Get taxonomy terms only of the WP_Query current posts
- get_terms orderby numeric
- get_term_link() returns incorrect url
- get a simple array of all of the term names that exist in all taxonomies
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- Get post id in a function when edit/add a post
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- How to get original custom taxonomy slug after the slug has been rewritten?
- How to get post’s current parent term ID?
- How to show only subcategories in parent category not parent category?
- Which PHP page is the Default Posts Page
- Function works everywhere, how to keep it to execute when creating a new post
- Limit Taxonomy Output in Conditional Statement
- Pagination on Custom Post
- Isotope Drop Down Categories Filter Function
- How to filter custom taxonomy term name, slug, and description?
- Exclude product attributes from taxonomy terms loop
- How to use mysql LIKE with wpdb?
- Reading settings in the home page precisely home.php
- get post id from wp_insert_post for get_template_part
- Create a a form for custom taxonomy terms
- WordPress custom taxonomy
- making php value numeric
- How to break up php code to avoid echo
- Taxonomy term description with style, only if the description exists?
- PHP displaying wrong custom taxonomy images
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- remove specificly the last tag in all posts
- How to change the author box selection on a post to a custom taxonomy
- How to hide a child category and show his parent category
- How to Send Pingbacks for all Posts in WordPress?
- How to retrieve taxonomy Metabox fields in frontend
- WP custom posts: filter results to custom taxonomy tag that corresponds to user meta field
- posts_per_page displays only 2 posts instead of 4 posts
- Send POST request to Flask app from functions.php file
- How to center all text body in single.php at once?
- How to insert text into post based on category – via single.php file
- Getting page / post URL on publish and / or update
- Displaying POST content with HTML tags and all
- Using Tag Groups: Displaying groups and adjacent tags of current post
- str_replace not preserving whitespace
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- insert thumbnail image from php script
- Can’t put a hyperlink on Featured Post’s Image
- how to display child terms with parent terms in custom taxonomy?
- Weird Behaviour: Not all WordPress Posts appearing
- Published custom posts missing
- Custom Taxonomy as Link
- WordPress get_post_meta issue
- Limit Taxonomy Parents
- Get category id for a custom category and display it in a class
- Insert wordpress tags below posts via functions.php
- Pass custom value to custom taxonomy
- Trying to see if page is category or single and displaying title with appropriate heading tag
- ISOTOPE – Missing/Invalid Arguement Get Terms
- How to modify this function to exclude also the post belonging to a specific category?
- How to display the date under the post title?
- How do I change the Go To Categories link in the term_updated_messages
- Display terms on product page with shotrcode
- Add multiple HTML attributes to an Elementor button
- WooCommerce: write featured image dimensions to custom fields in product’
- How do I get a function to work in single.php
- transition_post_status hook, works – but not if the post is new
- Get all taxonomies for all post types
- Include a specific post to the query_posts and remove it if it is already in the returned list
- Get value from shortcode to do something
- Can’t find infinite loop cause
- Creating a mobile site by adding a new class to the body tag from functions.php
- Displaying content on posts page based on category
- understand what code is doing when prepending /blog
- Adding an “Upgrade Subscription” button to an Elementor page
- Show a text if the post has written by author user role in WordPress
- Custom Bulk Actions handler not firing
- How to have Function of a plugin using global vars into a shortcode?
- HOW TO Insert Existing PHP Code to WOrdPress
- Understanding responsive imagery
- Why a class property becomes empty?
- get_the_term_list give me a whitespace
- Hide category by tag
- How to get meta box labels?
- How do I stylize selected comments?
- add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
- Background Tasks in a WP Cronjob?
- Tags being Inserted in html from plugin PHP not passing through the_content