I was building something similar a couple of years ago, here’s what I did, maybe it helps … (changed to your use case)
$result = new WP_Query([
'post_type' => 'location',
'orderby' => 'name',
'order' => 'ASC',
'posts_per_page' => -1, // all of them on one page
'tax_query' => [
[
'taxonomy' => 'services',
'field' => 'id',
'terms' => $custom_term->term_id,
'include_children' => true
]
]
]);
So you already are pretty close. What I noticed is, you use $custom_term->slug but it should be $custom_term->term_id as far as I know.
Related Posts:
- tax_query returning all posts instead of selective posts in WP_Query
- Custom post taxonomies as tax_query terms?
- Running a custom query inside another cpt single and trying to grab a variable
- tax_query showing no results
- Taxonomy: Why ‘with_front’ => false DOES NOT WORK?
- Query Custom Post Type taxonomy type based on page
- The Operator “NOT IN” Does Not Work In tax_query
- Sorting a list of posts displayed under a list of associated terms (which should be sorted without initial articles)
- How to get the parent’s taxonomy?
- Adding a term name from a custom taxonomy assigned to a post link displayed by a wp_query loop based on another taxonomy
- Combine tax_query and meta_query in WP_Query
- List all custom post type posts from a given category?
- WP_Query tax_query on ACF post_object
- Paginated Taxonomy Term Archive including one post per term
- Show Post Count of a Category
- Exclude specific taxonomy term when using wp_get_post_terms
- Fetch taxonomies by custom post type id array
- $wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies
- Why does querying on post_tags (which has been applied to custom post types) only return posts?
- Query Multiple Taxominies Across Multiple Post type’s
- How to show CPTs in term archive
- Query custom post type by category slug
- Custom Post Type Taxonomy Filters
- How to Filter custom post type by taxonomy?
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- Why is this query not working? (Standard posts + custom post type)
- Several post types on WP Query by tag and taxonomy
- Using meta_query and tax_query at the same time
- Custom Widget WP_Query problem
- How to conditionally redirect to the post from a taxonomy page?
- How do I display the grand child items of a taxonomy term?
- can these 3 queries be re-written as 1 query?
- How to display Related Posts based on number of taxonomy terms matched
- tax_query not working in template
- Variable not working in WP_Query
- WP_query – Filter by tax_query and meta_query using multiple select
- WP_Query parameter conflict
- Query all post and CPT from 2 specific taxonomies AND by ACF custom field
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- tax_query (if the terms are empty)
- Sort results without WP_QUERY?
- I have custom post type with custom taxonomy. But not found the taxonomy page..
- Get posts by category name
- wp_dropdown_pages with tax_query clause
- How to display posttypes and taxonomy in standard posts, not in a separate label?
- Query Custom Post Type by Taxonomy
- Query all posts under one taxonomy? Why is my code not working?
- “Menu order” being ignored when querying posts from a parent taxonomy with “include_children” set to true
- Custom Query: Multiple CPTs and a taxonomy filter
- Page that lists publications by classifying them by taxonomy
- custom post type and a “sticky” position taxonomy
- Filtering posts based on three taxonomies
- Custom post type query with taxonomy
- Display Custom Post Type Based on Taxonomy With WP_Query()
- wp_query with meta_query and tax_query
- How to search through all child taxonomies using WP_Query?
- WP_Query for custom taxonomies showing posts from non-specified terms?
- Custom Taxonomy – fields
- tax_query not working?
- One of my headings is mysteriously coming up as a link in my CPT Archive
- Showing taxonomies with terms that are attached to custom post
- WP Query tax_query not returning posts
- Not able to get my custom search result using meta_query and tax_query together?
- Error get_posts with Custom Taxonomy and OR relation
- Query for a custom post taxonomy
- How to show post which has the specific taxonomy terms?
- Displaying WordPress posts from post and custom post type in custom taxonomy
- Query breaking with ‘posts_per_page’ => -1
- Use Tags to Query Associated Multiple Posts and Get The Average Of Custom Field Values
- How to display elements of different post types?
- Storing/querying custom date data
- category_name not working in WP_Query
- Cannot query custom post type taxonomy from theme options array
- Using tax_query to get single post per category
- WP Query Conditionally query meta and taxonomy
- How do I get parameters from the URL?
- Creating “static” taxonomies to choose from, inside custom post type?
- How do I dynamically populate wp_nav_menu from a custom taxonomy?
- Filtering a WP_Query meta_query by numeric values isn’t working
- Order posts by (hierarchical custom) taxonomy terms and term children
- How do I list terms of a custom taxonomy at i.e. domain.com/brands/
- Taxonomy-{taxnonomy}.php is not working
- Display all Posts and only certain Custom Post Types with meta fields
- How do I get array of types associated with a taxonomy?
- Show category ID on custom post type
- Isotope Filtering with Bootstrap Tabs – Custom Post Type Query Loop in each Tab (Have to click twice to filter)
- creat filter with wp_query
- Sort entries by date mixing two post types
- Unable to link categories to custom post type using standard function
- How can I group posts by months and years?
- Displaying a div from an assigned meta_value when on a page
- Getting a custom post’s custom field based on another custom post’s custom field select
- WP_Query not resetting after wp_reset_postdata
- Display 1 Post per taxonomy with polylang
- Ordering by meta value not working
- How to sort by multiple values in a nested WP_Query
- SQL LIKE in WP_Query
- How can you use a page for a custom post type?
- CPT Efficient way to display posts from different categories with custom query
- Values inside a custom field to determine which category posts to display