Don’t use get_the_term_list()
as it returns an HTML string, which makes comparing more difficult.
Use wp_get_post_terms()
(Codex link) instead. It can return an array, and then you can use something like array_intersect()
to get the terms that match.
Your code should look something like this (I haven’t tested this):
$course_terms = wp_get_post_terms($course_post_id, 'course_type'. array('fields'=>'slug'));
$testimonial_terms = wp_get_post_terms($testimonial_post_id, 'course_type'. array('fields'=>'slug'));
$matches = array_intersect($course_terms, $testimonial_terms);
if (count($matches) > 0) echo "matching terms";
Related Posts:
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Control content before and after custom post type loop
- Combine multiple separate lists into one
- Show parent category and subcategory once in while loop
- Add active class to foundation 6 tabs while looping categories
- WordPress query posts by custom post type not workng
- WordPress Custom Post Type and sort by Tags
- Order by custom field attribute
- Looping taxonomy in taxonomy?
- Display custom field of specific post where post title matches variable
- wp_query to find posts by year and month
- Create a random unique 6 digit number as custom field for custom post type
- How to output wordpress custom tags separated by comma?
- Custom Post Type Loop within Shortcode
- Weird problem happening with custom taxonmy when creating/updating posts
- get_template_part for each level of taxonomy term
- Filter by custom taxonomy slug on a custom post type
- Normal pages as children of my Custom Post Type
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- Only show posts from a certain category?
- Very Slow Page – How to Optimize # of Queries?
- Display CPT posts based on specific taxonomy
- How to display selected taxonomies by their parent
- Custom Field Order by Last Name and First Name
- get_posts of Custom Post Type AND Custom Taxonomy
- WordPress Genesis custom taxonomy archive shows 3 repeats of each post
- Custom Post Type Loop throws 500 error when used in widget
- Am unable to reset a query properly
- get_attached_media() on author page not working
- Received nothing after executing AJAX post function
- How to make sure content doesn’t display if selection is empty
- CPT + CMB2: data not displaying for only first post in loop
- Get next and previous 3 posts in a term in single post page
- Get custom post type list for every category shortcode
- Loop custom taxonomy to get lists of cutom post types?
- How do i calculate the total of values of custom fields in custom post types?
- Custom loop with multiple taxonomy queries
- I would like to have different styles for my posts based on the content of each post
- Checking if Post Title is Unique as Loop Criteria
- Custom post type multiple loop by taxonomy term
- List custom taxonomy specific to one custom post type
- Show a Category X’s custom post type on Category X archive page?
- Custom Tag Description unable to display just below and outside of the Loop
- Display all taxonomy terms, add class if term applies to current post
- Return the latest post from a custom Taxonomy and Post Type
- 404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- Group CPT posts by custom taxonomy
- What’s the WP way to load remaining custom posts?
- Categorize custom post type
- Custom post type editor with dynamic selects, one drop down populating a second second drop down not working
- Display Custom Taxonomy Alphabetically
- Full Custom Post Type List Organised by two Taxonomies
- Listing all term items alphabetically / sorting loop
- Display related custom taxonomy posts in sidebar
- Only show posts with date of today or in the future (i.e don’t show past posts)?
- Different Category system needed for the Custom Post Type
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Three Most Recent Posts, One Per Term
- get_the_title() is returning results from previous loop
- Fetch data from two custom post types and create multidimensional array for output to html table
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- Get Posts List of Current Selected Custom Taxonomy in Shortcode
- Page that lists publications by classifying them by taxonomy
- Custom archive page for custom taxonomy and pagination issue
- CPT loop doesn’t seem to account for post date?
- How to display list of custom post taxonomy terms and their posts (if any)?
- Custom front-end form for adding post – Category problem
- set object terms after some some time of published post – functions.php
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Get all post under custom post type grouped by custom filed value in custom taxonomy
- Check that a slug is present in the get_terms request
- Custom post type paging return home page
- Pagination not working in custom post type. Help
- Assigning categories to custom post types via a front-end form; only works for native post type
- when looping through custom post data not appearing
- Excluded Custom Taxonomy Term Posts Displaying in loop
- pagination problem listing custom post types of taxonomy in wordpress
- Accessing download link from the loop with WP Download Manager Pro
- Custom Post Type has wrong label and is not found when called by a loop
- Some posts not displaying by taxonomy term
- Taxonomies are not showing in the category dropdown
- Looping to organize and display custom posts by category using PHP and WordPress
- posts_per_page is not working by term
- Filter Custom Post Type Posts by Taxonomy
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- Adding a Section for Visitors
- Change Search display for Custom Post Type
- Why is my loop not populating the page with my custom taxonomy terms from my custom post type?
- List all posts associated under custom taxonomy
- Custom search for a custom post type in WordPress
- How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta
- Custom Taxonomy – fields
- % encoded URL giving 404 error in WordPress
- CPT: multiple loops with different terms
- WordPress trying to query two custom types to get child from the parent