The first two methods aren’t working because the ‘cat=” and “category__and’ query variables are only for the standard post type (built in) Category taxonomy conditions.
The 3rd method is nested in multiple foreach loops which could be the cause of the duplication. I think it will work like you want if you just remove both those foreach loops and let the query stand on it’s own. Currently you are repeating the query for every term in both taxonomies.
Instead of using foreach, just grab the the current terms once by replacing this:
echo '<h1 style="margin-top:10px;">'.$custom_term->name.'</h1>';
with something like this:
$term1 = get_term_by('id', 6, 'ait-dir-item-special');
$term2 = get_term_by('id', 39, 'ait-dir-item-category');
echo '<h1 style="margin-top:10px;">'.$term1->name.' and '.$term2->name.'</h1>';
Related Posts:
- exclude category from get_posts?
- Get id of category from drop down menu
- Show post only if match all categories
- Show recent posts from one category on a non-WP site
- get_posts and multiple categories
- Trying to only display 1 category using get_posts
- Get link which associated with a specific category and tag
- Get posts from specific taxonomy term
- List all posts in a category with query_post() function
- Hooking to walker_nav_menu_start_el to insert list of subpages
- get_posts ignoring ‘category’ and displaying all posts
- How to pull a list of posts in a category while exluding posts in subcategories of the category
- How to Link to Most Recent Custom Post of Same Term
- get_posts() from parent category only using a shortcode
- Exclude parent category when getting category posts by slug
- Exclude categories from homepage not longer working
- Showing posts from 2 categories only on category.php
- get all categories’ latest post in one query
- Load the last post of a category
- get_the_category return empty inside loop
- Get posts base on category ratio of more then two categories
- Media Library Category Exclude Tree
- not empty categories don’t show in menu [closed]
- how to call the category of the post
- How to create a custom loop ordered by Categories on a Page Template?
- How to change category id on get_posts array
- get posts from 2 categories. (2 posts)
- how to ask if in two categorys inside if
- How to add featured image for category (without a plugin)?
- Category archive by year with permalink support /category/YYYY
- How do I get the category URL from get_the_category?
- Default WP Gallery – show only galleries of a certain category
- How to tax query X number of posts related by tag first, then by category if not enough in tag-related
- Exclude sub category posts from category display
- Automated adding of one tag to all the posts in a category
- Query only Posts from Both of Two Category?
- Deleting All tags except categories Wp database
- Action hooks returning old category instead of new category
- Category checkboxes in upload modal
- How to mass-insert categories?
- How to put enctype=”multipart/form-data” in categories form?
- What is the advantage of using header-catname.php over is_category(‘catname’);?
- Custom WP_Query for current category (in category.php)?
- Why is get_the_category() saying that I have two categories?
- Custom sidebar on category pages
- Insert Into Sub-child Menu
- How do I get the category slug from wp_dropdown_categories
- Change the category of all posts in it
- How to display only posts assigned to a particular, isolated, subcategory
- How to hide some categories in category list under post in wordpress?
- exclude categories from search results
- How to categorize posts under Category 1 and Category 2 which are separate lists of categories, and display them as separate lists in widgets
- Refine/Filter the Search Results by Category
- Putting a Category of posts under a Page
- change recent posts based on category
- Why is it so hard to show the URL of the current category and how to do it?
- Where and when does WordPress invoke routes
- Getting category URL with hyphens, not spaces
- How can I change the tooltip in the_category?
- Category.php loads first before page.php?
- wp_update_post is not updating category
- How to get Next/previous_post_link to go through articles in top parent category
- What’s wrong with my wp database query?
- Fix Warnings that shouldn’t be necessary to fix
- how to get correct category of a post in case of multiple categories?
- Show button only for certain Woocommerce Product Categories
- get listed category’s id?
- Length of Category Names
- Category url generate 404 error
- Notice: Undefined variable: category_id
- Is it possible to create an alias/custom taxonomy for a category name?
- Style a category from category list
- Add a category on all archive category pages
- Multiple category columns and post counting list in wordpress Homepage
- Check for parent category
- add current-cat class to single post page
- How to add content above footer in posts from specific category
- Problem with wp_create_category
- Problem with pagination block in Gutenberg
- Product category display in tabs
- Sending all categories associated with a post to Google Ad Manager for use with .setTargeting
- Pull in an “Include” file based on a WordPress Category ID
- Sort categories by custom field in WordPress admin
- Why is URL Slug Saving Differently From How It’s Been Defined?
- Related to genre and category
- Get permalink to latest post in category
- How to noindex, follow a specific category wordpress?
- get taxonomy list in a page in the wordpress
- How to load terms of a custom taxonomy of a product in woocommerce cart page
- How to exclude category and post_tag taxonomy while displaying custom taxonomy?
- Group Posts by First Letter of Title categories
- Alphabetize all but one category
- How to make 10 post of one category
- Listing category
- Anyway to hide a Category in the Categories section when adding/editing a post in WP Admin?
- Showing one post from each category, paged?
- Custom permalinks structure
- Weird html output of single_cat_title – is not inside of the html element?
- Custom EndPoint not working when strip child category in URL
- How to add custom prefix before category base for category page URL?