Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Get all terms linked to a post and include those who not connected from get_terms and sort

You just need to get the term id’s of the terms assigned to a post, and then exclude those terms from get_terms()

You can try the following (Just note, the syntax for get_terms() changed in v4.5, I’ll be using the new syntax)

$args       = [];
$taxonomy   = 'my_tax';
$post_terms = get_the_terms( get_the_ID(), $taxonomy ); // Use wp_get_post_terms() if you need special ordering
// Only display the post terms and exclude them if there are terms and no WP_Error
if (    $post_terms
     && !is_wp_error( $post_terms )
) {
    $term_ids = [];
    // Display the list of post terms
    foreach ( $post_terms as $term_object ) {
        // Display term data 

        // Build an array of term ids
        $term_ids[] = $term_object->term_id;
    }

    // Set these id's to the exclude parameter
    $args['exclude'] = $term_ids;
}

// Now we can get the list of all term
$args['taxonomy'] = $taxonomy;
$terms            = get_terms( $args );
// Check if we have terms and no WP_Error
if (    $terms
     && !is_wp_error( $terms )
) {
    // Display the terms
    foreach ( $terms as $term ) {
        // Output the terms as needed
    }
}

Related Posts:

  1. Explanation of update_post_(meta/term)_cache
  2. What is ‘term_group’ for ‘order_by’ in get_terms()?
  3. Order get_terms by term meta
  4. Display all the subcategories from a specific category?
  5. Get parent id by term id
  6. How to get_term_children output in alphabetical order?
  7. When to / not to use wp_get_post_terms vs get_the_terms?
  8. Why does WordPress combine a term with the same name in the wp_terms table?
  9. Correct use of get_the_terms()
  10. Get multiple term IDs by slug, and then exclude them in get_terms
  11. wp_list_categories: order by term order?
  12. Child terms from multiple parents?
  13. I have a term_taxonomy_id — is there an API call to get the taxonomy?
  14. Exclude Child Terms From Parent Posts
  15. same taxonomy for several post types: how to hide empty in a specific post type?
  16. How to sort terms with diacritical signs?
  17. wp_set_object_terms creates relationship to REVISION?
  18. get_terms(); show private posts when logged in
  19. Get category ID after wp_insert_term
  20. How do I access a single term from a post?
  21. How to get all term meta for a taxonomy – getting term_meta for taxonomy
  22. Prevent Selected Terms Rising to the Top
  23. How to order get_term_children output by alphabetic order
  24. How to update incorrect post count in taxonomy?
  25. Term begins with a letter
  26. get_post_terms not working as expected
  27. wp_update_term not creating new unique slug
  28. has_term() does not return when term is assigned post?
  29. Exclude a category from the filed under list
  30. get_terms() but with additional dimensions?
  31. Wp set post terms not work
  32. how is it possible that using wp_insert_category throw a fatal error?
  33. How to Get All Taxonomies AND All Terms For Each Taxonomy With Post Count Zero
  34. get_terms only show term if there is a post using it
  35. Get post terms for multiple posts at once?
  36. wp_update_term: How could i update the “name”?
  37. Get the Term List – Ordering
  38. Adding Multiple Values to a Post Meta Key
  39. Reduce / optimize calling of wp_get_object_terms() when generating permalinks
  40. Check if an array of posts has posts from a specific category
  41. Get only one product category woocommerce
  42. How to trace/fix false $term->count, rogue term relationships?
  43. How to order and count get_terms by specific post type?
  44. How to use a Term Meta Field as a link
  45. get_the_terms() to show all custom taxonomies
  46. Get those terms with a specific meta key value
  47. get_terms() order by term_meta
  48. Difference between get_category, get_term_by and get_categories
  49. get_terms() for custom taxonomy related to another taxonomy
  50. get_terms from registered taxonomies not working
  51. Change description on specific WooCommerce product status change
  52. What is the term shortlink structure?
  53. get_term_by “name” not working with & in name
  54. I want to loop through Woocommerce Product Catogories and show them in dropdown
  55. Invalid argument supplied for foreach() in search.php
  56. setting taxonomy term to bulk posts using ids
  57. Does WordPress limit the length of slug names for Post Meta or Terms?
  58. Do I have to set parent when set post term?
  59. How do I determine if a certain term is in an array?
  60. Modify automatically generation of slug when term is created
  61. Display custom taxonomy on single post
  62. get_terms ‘number’ parameter does not appear to work
  63. Does get_terms() use any sort of caching on its query?
  64. Question with get_the_term_list
  65. Group child category IDs based on their parent category
  66. 404 on term taxonomy archive pagination only with some terms
  67. Clone Terms of one taxonomy to another
  68. Custom Template for one Taxonomy Term
  69. Unset actions for terms parent only
  70. Get random out from get_terms()
  71. Create / Close Div in Array [closed]
  72. Conditional based on number of specific custom taxonomy terms in archive.php
  73. Categories order with get_terms_args not working in 4.7
  74. Getting all categories even with no products under it?
  75. Sticky posts per category
  76. Faceted search with WP-API data
  77. Show List of Terms (not posts) that have been Recently Updated?
  78. import_id parameter for wp_insert_term to create custom ID for category
  79. Programmatically add posts add and assign postmeta and assign terms
  80. When using the get_terms and trying to order the terms using the ‘order’ and/or ‘orderby’ does not work
  81. get_terms – name__like a number
  82. Query to get term id using post id?
  83. Why does wp_get_object_terms add a period after terms are output?
  84. Conditional Statement with Multiple Terms?
  85. How to apply comma separation,strip_tags and orderby to wp_get_object_terms
  86. How to get a post’s associated taxonomies and terms in wp api v2
  87. wp_set_post_terms is assigning only the last of several terms to a post
  88. wp_set_object_terms not working inside loop
  89. Leveled – Terms foreach
  90. Add Taxonomy Description with wp_set_post_terms
  91. get_the_terms() not returning expected result
  92. Add class to first post queried
  93. wp_insert_post() does not support variable
  94. How to force acceptance of site terms on first login?
  95. Missing term_id value
  96. Add HTML to Term Description
  97. Get the ID of category page with or without any posts
  98. single_term_title() running before get_the_title() [closed]
  99. Get terms within a custom taxonomy
  100. WordPress Term for Custom List
Categories terms Tags post-meta, terms
Shared account / dual blogging in WordPress
How to remove some metaboxes for CPTs?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress