In looking at the WP_Tax_Query class in /wp-includes/taxonomy.php, I found that there is a ‘include_children’ option which defaults to true. I modified my original get_posts() call with the following, and it works great:
$pages = get_posts(array(
'post_type' => 'page',
'numberposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'taxonomy-name',
'field' => 'term_id',
'terms' => 1, /// Where term_id of Term 1 is "1".
'include_children' => false
)
)
));
List of more query parameters: https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
Related Posts:
- Get the the top-level parent of a custom taxonomy term
- Determine Term depth
- Get taxonomy name of current post
- Determine if Term has Grandparent/Great-Grandparent
- Custom Taxonomy Only Showing Top Level Terms in Admin?
- How to set hierarchical terms to a post using wp_set_object_terms
- Hierarchical display of custom taxonomy
- Display hierarchical subterms of custom taxonomy based on depth
- Hierarchical Taxonomy Terms Select Menu Output with selected=”selected” Set
- Rewrite rules for varying nested terms of custom taxonomy
- List Posts For Terms Of A Custom Taxonomy For Any Post Type
- How to get posts that contain multiple terms from multiple taxonomies?
- custom hierarchical taxonomy and custom post type list contains surplus posts
- URL rewriting taxonomy term
- Orderby taxonomy term id using get_posts not working
- Taxonomy term breadcrumb; how?
- Determine if Term has Grandparent/Great-Grandparent
- get_term_children for immediate children only (not grandchildren)
- Is there a way to ‘Lock’ a Taxonomy?
- Hide the term description on the term edit page, for a given taxonomy
- get_term_by not working when in functions.php
- Creating a non-removable taxonomy term
- Can I lock down custom taxonomies on a parent term level, but not a child term?
- Exclude specific slug in ‘get_terms’
- Return only the custom sub-term for custom post type, do not echo term-parent
- wp_insert_term is adding a term that has no name
- Get terms from multiple taxonomies
- get_terms showing link to category even if all posts are drafts
- Custom Taxonomy Relationship (ex: plant classification)
- Retrieving custom taxonomy in order, but excluding specific tax IDs
- Taxonomy query for children of parents
- Group posts that matches a term in a loop
- Help building array hierarchically with taxonomies (to get posts)
- How to display term description in empty terms archive?
- Checking if a Page has an Associated Term?
- What are terms and taxonomy, how they related to post and how these three are stored in database?
- Get multiple term objects by ids
- get_terms custom order
- Limits amount of terms displayed? Is it possible?
- How to List Parent Term Links for Custom Taxonomy With & Without Children?
- Get Bottom Most Level Taxonomy Terms?
- How can I get WP to build a feed based on multiple taxonomy terms
- Check if term is in a taxonomy?
- Get child product categories from parent product category in WooCommerce
- get_term_children doesn’t return an array of children terms
- How to show only terms by id or slug on edit-tags.php (custom taxonomy manage page) for a custom taxonomy
- Display the description of taxonomy terms
- get_terms adds slaces to the resualt
- Term count by user
- get_term and get_term_by return null or false, even though term exists
- How to add contents of a custom field to a taxonomy term list?
- one term two taxonomy’s?
- Custom while loop for hierarchical display of a taxonomy
- Getting WooCommerce product related child categories
- Custom Taxonomies not retaining hierarchy while importing from one site to another
- Using custom taxonomies to display hierarchical URLs?
- Query posts from a child taxonomy term id
- get_terms() duplicate first term of a custom taxonomy
- Having Issue on Passing Variable into HTML Class Tag
- Echo custom taxonomy slug
- Admin (All posts) stop responding problem
- Query posts using custom taxonomy and selected terms
- Proper use of wp_get_object_terms
- Output all terms in a custom taxonomy and add a “active” class only to the ones attached to the current post
- tax_query: Don’t show posts with parent term when they have a corresponding child term applied
- one post per term taxonomy
- How to check if a post has at least 2 terms from a custom taxonomy attached?
- How can I change the output display of my pagination?
- Can’t get taxonomy ID for each post on archive page
- Terms change id after importing
- delete term from taxonomy and assign in new one
- How to add a date creation field when a custom taxonomy relationship is created?
- Adding Child Terms Programatically – No Warning but No dice either
- Show related posts on single.php, grouped by taxonomy terms, with Advanced Custom Field post object selected
- Running a function only once when a taxonomy term is changed
- Set post terms by term id
- Displaying my custom taxonomies in a using the_term_list()
- Use wp_list_categories to list parent categories from actual term
- Trash Bin for Categories?
- using wp_insert_term to create custom terms for a custom taxonomy from frontend form,
- is there a way of getting term children that only shows those from two taxonomies
- Display term picture of each post in a loop
- Get Terms of custom Taxonomy of products with certain Product Category
- Problems using get_the_terms in a plugin
- How to add a shortcode function that returns the taxonomy slug of the actual post within the loop
- Tree view wp-admin terms
- Retrieve the child terms by having the parent’s information
- add pagination in wordpress page template
- Order get_terms by count using a custom taxonomy hierarchy
- How to create a non removable taxonomy term?
- WordPress taxonomy terms archive template help
- How to define a custom hierarchy for terms?
- Why get_terms() behaves strangely when being called in admin (for use in meta box)?
- qtranslate-x problem with custom term description
- Sorting terms individually for each post
- get_terms returns array starting at 4
- Getting grandchildren of a post with a specified custom taxonomy?
- Multiple category lists on one page
- get_the_terms inside save_post gives old terms
- Hide empty categories on widget