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
- How to change post date and post time in WordPress automatically with a function
- Put ACF function output code the_terms
- Get my site session in wordpress?
- WordPress Options Page Theory Question
- Make Current/Active Page Number a Link (WP_LINK_PAGES)
- How to make modifications only to certain elements of an HTML string on the server-side?
- WP Insert Post and then go to post
- How to list posts from a plugin taxonomy?
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Returning data instead of echoing/printing
- Override a function defined in wp-includes/comment-template.php
- Edit the_category (); for a hierarchical display
- How do I modify the custom footer text and get theme version number to show in wordpress admin?
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- Show meta box only for default page template
- Illegal string offset in PHP function
- Need to put a script above tag in header.php – WP 5.7.1
- Display related posts without a plugin
- How to use html inside a functions.php code?
- Multiple meta_key in one global $wpdb;
- Nested “do” and “add” Actions is possible?