You cannot make up your own arguments – rather than replacing the 'category'
argument with your taxonomy name, use 'tax_query'
.
See “taxonomy parameters” section of the codex on get_posts.
$args = array(
'post_type' => 'event',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'eventcategory',
'field' => 'slug',
'terms' => 'nice-events',
),
),
);
$your_query = get_posts( $args );
// do something with $your_query
Alternatively, you could make use of the WP_Query
class:
$args = array(
'posts_per_page' => -1,
'post_type' => 'event',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'eventcategory',
'field' => 'slug',
'terms' => 'nice-events'
),
),
);
$your_query = new WP_Query( $args );
// do something with $your_query
Related Posts:
- Getting the Intersection of Two Custom Taxonomy Terms for a Custom Post Type?
- How to get only one category of custom post type?
- How to get the intersection of two terms both from different custom taxonomies
- custom hierarchical taxonomy and custom post type list contains surplus posts
- Get posts by category name
- Can’t pull posts of a Custom Post Type based on the custom taxonomy of the CPT
- Display a random customposttype2 excerpt in single-custompostype1.php that shares same taxonomy
- get_posts wont produce a list of custom type from a given category [duplicate]
- Query a custom taxonomy in a function to create an csv file
- week days sorting based on starting day
- Error get_posts with Custom Taxonomy and OR relation
- Why get_posts() returns empty array while I am trying to get posts from some specific taxonomies and work properly with others?
- WordPress get all post with like in terms [duplicate]
- Decrement term in for each
- Fetch posts list from fist CPT taxonomy term and list under 2. CPT
- Create a hierarchical list of posts that’s grouped and nested by category
- Remove Custom Taxonomy Metabox from Custom Post Type Screen
- Get terms by taxonomy AND post_type
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Get Custom Taxonomy ID within loop
- Custom Post Types not showing on Custom Taxonomy archive page
- Remove Trash / Delete option for Custom Post Type / Taxonomy
- How to filter custom post types by custom category taxonomy
- Highlight menu item when on a custom post type?
- How to setup a Custom Taxonomy Term template
- Admin to user notices – best practices?
- How to select one major category (or custom taxonomy) for a custom post type?
- Custom taxonomy & post slug permalink
- Retrieve a specific field from taxonomy term through advanced custom fields [closed]
- Custom Taxonomy List links being re-written
- front end radio custom taxonomy with custom post type
- Child and grandchild taxonomy listings – 404
- Limit taxonomy results to a single cpt
- Bulk 301 redirect for custom post type
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- RSS feed for dynamic set of custom taxonomies terms
- 404 Error with Custom Post Types and Taxonomy
- Making pages also serve as taxonomies? Or give full pages to taxonomies?
- Display custom post type category taxonomy
- How to make a custom taxonomy selectable in post publish area?
- Are there sub-systems in WordPress that would employ data structures beyond CPT that a `get_posts` won’t be able to catch?
- Remove standard meta boxes from custom taxonomy
- List Post Title by Last Word Then Second Last
- Custom Post Type / Two level deep taxonomy (cat. and subcat.) uri problem (error 404)
- Customize Query for post
- Custom loop with multiple taxonomy queries
- Tax query not producing any results
- Display post as term id
- How to filter wp_list_categories output with some custom post type meta query?
- Custom post type editor with dynamic selects, one drop down populating a second second drop down not working
- Display latest x posts from all categories in Custom Post Type/Taxonomy
- Sitemap generation
- Why cant I add a custom post type to a custom taxonomy?
- Show Custom Taxonomy title in loop
- WP the_posts() on single-cars.php get category link
- tax_query not working in template
- Custom Post Type Dilema – How do I categorise by country?
- Main query not querying any posts in custom taxonomy template
- Filter posts by tax (dropdown) and meta value
- Not able to export large no. of posts in csv
- Can I query posts by taxonomy conditionally based on post type?
- Which file/template is in charge of taxonomies for custom post types?
- How to get dropdown instance value in WordPress custom Widget
- Include custom post type custom taxonomies in Categories widget
- Custom sidebar for custom post type
- Changing CPT slug and taxonomy already registered in parent theme
- Show post count number assigned to custom taxonomy
- Get Terms from Custom Taxonomy and Current Post
- Display next 3 posts based on custom taxonomy
- Check when the post type changes, and display content
- Loop and add Specific Categories and Products Images
- custom post archive URL is wrong
- Display latest post of taxonomy
- Custom Post Type with Different Sets of Post Content?
- Add a class to a div if custom post type has specific terms?
- Custom post type paging return home page
- In child theme, add CPT to custom taxonomy registered in parent theme
- Custom taxonomies not displaying in some custom posts
- Custom taxonomy returns 404 even with saving permalinks
- Static Front Page not working for custom theme
- WP_Query to display number of custom post type filtered (order by) taxonomy
- Custom post type shortcode with taxonomy attribute not working and no errors
- Live search by custom tag
- Set a Default CPT taxonomy by taxonomy id
- Custom taxonomy terms registered not showing when added in child theme
- Custom post edit page permalink links to edit page rather than the post
- Not Able to List CPT Based on Taxonomy Term
- Show tags of custom post types in WordPress
- Filter Term By Parent Term – Custom Post Type
- Display all Custom taxonomy terms and their relevant custom posts
- Best way to group posts based on custom post type terms
- Render custom taxonomy query as single template
- Custom meta-box for all custom post types
- Remove custom taxonomy ‘post-type’ from post URL
- Building a List of Posts grouped by custom taxonomy as the section header only to be displayed if at least one post is in that tax
- Custom My account page and custom page for editing posts
- Listing all custom post types using a specific term on the said term’s template page, in groups
- Require Custom Taxonomy for Custom Type
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- post__in select all custom posts and not the selected array of ids