You should be able to change these lines
if ( !empty($terms) ) {
foreach( $terms as $term ) {
echo $term->term_id . ',';
}
}
to this:
if ( !empty($terms) ) {
// create an empty array
$procedures_to_include = array();
foreach( $terms as $term ) {
// now instead of echoing, add each term to the array
$procedures_to_include[] = $term->term_id;
}
}
Basically instead of echoing manually, you’re creating the array to begin with, and in your get_terms
call you can just use $procedures_to_include
directly:
$terms = get_terms( array(
'taxonomy' => 'procedures',
'hide_empty' => true,
'include' => $procedures_to_include
) );
Related Posts:
- Can I force WP_Query to return no results?
- WP_Query and next_posts_link
- How to list some posts first in the loop based on post id
- Use WP_Query with have_posts()?
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- Get array of posts from the current archive page loop
- WordPress Custom Query to show posts from last x years
- How to order posts tag by tag?
- Loop through all tags & output posts in alphabetical list
- Pagination with 5 posts per page
- In loop: posts have thumbnail AND other variables
- Add inline HTML to posts published within last 24hrs
- Move posts to top of WP_Query if in certain Taxonomy?
- Display different number of posts from one category on the different pages
- How to display 3 different loops in 3 columns on homepage
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- WP_Query to get posts in a specific category and post format
- Implementing an OR statement to wordpress wp_query
- Get List of all the Authors
- Can’t get drafts with WP_Query using post_status parameter
- WP_Query doesn’t get sticky post at the top, when used in a page template
- Prevent duplicate post from dynamic multiple loops
- if/else on custom query gives 200 OK when condition not met?
- Refine search results using WP_Query
- Multiple Loops Inside a Function
- How to pass many ids in post__in?
- How to show subcategories using loop?
- Sticky posts are not showing at the top of category posts
- Storing query variable and then using wp_reset_query
- Sub-loop / nested loops Best Practices
- Show Sticky Post at the top but do not show again in the loop?
- Can I set my WP_Query to be a Main Query?
- How do I run through a WordPress loop called from a filter function?
- How do I get the title of a category in a custom loop?
- Group and list posts by custom taxonomy
- Show scheduled posts in main loop but not in WP_Query?
- Change query based on post type while staying in loop
- Get a list of posts with associated meta_value
- Out Of memory issue on post per page parameter
- $WP_Query: How to display excerpt on first post only
- Check if loop has any categories?
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- How to make search for posts using get method?
- How to get list of posts from permalinks?
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- Change query from cat id to slug or name?
- How do I get my custom query to work with search results after the first page?
- Using Wp_Query without the loop?
- Custom WP_Query id
- Assign custom parameter to each post in query
- Exclude recently updated post from custom WP_Query using multiple loops
- get_posts output always same post
- difference between querying database and using the loop
- Stomping WP_Query in author archive to facilitate pagination with custom queries
- posts archive page – closing WP_Query loop correctly [closed]
- AJAX Breaking Offset Argument In WP Query
- How does WP generate the default $query in WP_Query based on the URL?
- Continue or break the while loop
- how to get category`s slug in WP_Query loop?
- Loop posts based on permalink term
- How to remove only the latest sticky post from the loop
- How I can repeat 2 HTML templates in a WordPress Query?
- Does putting queries within loops cause an issue on WordPress?
- Offset WP_Query by negative 1
- WP_Query orderby random do not repeat infinite scroll – one loop
- Advise on Templates for Custom Queries
- Query WP Page for Buddypress Group Home [closed]
- $post in wp_query?
- How to pass the current content of $wp_query to a new page?
- How to make the ‘request’ filter work?
- How to separate two columns from one content on a page template?
- Can I alter the main loop to ‘orderby’ a custom callback?
- How do I stop the same post showing multiple times in a archive?
- WooCommerce | AJAX | Product Pagination | Help me implement Ajax Pagination
- Avoid removing duplicate posts
- how to get custom attachment url?
- WP_Query & Duplicate entries
- Regarding a custom loop and output HTML tags
- Repeat array inside array through while loop
- What’s causing an infinite loop?
- pages shortcode filtering by category
- Second WP_Query loop shows data from main query
- Meta Query if Values Don’t Exist
- Get post Number with local loop and template
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- Calling a function with WP_Query only ever brings the first result
- display post multiple times based on array of dates
- Problems with WP_Query, Loop, a condition and Posts per Page
- WP_Query secondary query failing
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Custom search (wp query by custom fields)
- Sorting is not working in WordPress WP_Query
- Add custom WP_Query after the first 3 posts
- Limit the number of posts from a specific category on index.php
- Query for page content, and query for posts on the same page?
- How to show featured post first, then separate loop for other posts
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- How to get rid of extra Untitled Article in html5 document outline when using new WP_Query?
- after refresh the id that shows correct in first time click, changes to 1