Is it possible to remove custom post types from WP_QUERY that have a same shared custom taxonomy so that only one custom post type associated to that custom taxonomy is returned?
Example: Get an Items custom post type, returning only one Item per a custom taxonomy.
On a taxonomy-types.php page, I’m using WP_QUERY to get the Items custom post type. Then, wp_get_object_terms to get the Models custom taxonomy for the Items, and displayed that. However, I can end up with duplicate Models displayed because WP_QUERY is returning all Items and not one Item per unique Model.
Thank you for your help!
Thanks guys. I think I may have found a solution.
What I did:
taxonomy-types.php
, get all Items for that type using WP_QUERY.get_the_terms()
to get taxonomy Model for each Itemin_array()
function and a$model_ids
array for unique Model checking$item_ids
array'post__in'
set to the$item_ids
arrayIf I understand what you want, when you register a CP on your theme, there is an option “exclude_from_search” set it to false and it won’t show on search results.
For more information check: Register Post Type