I prefer using using the array form…
$gabquery = new WP_Query(array(
'post_type'=>'courses',//The name of the post type
'posts_per_page'=>5, //Use this rather than showposts
'tax_query'=>array(
array(
'taxonomy'=>'my-custom-tax', //Your custom taxonomy name
'operator' => 'IN',//NOT IN & AND also available
'field'=>'slug',//or you could select by ID
'terms'=>array('my-term-slug')//Get posts with this term (or ID if above is ID)
)
)
));
The above queries posts of type ‘courses’, limits the number of posts to be displayed to 5 per page, and selects only posts which belong to the ‘my-term-slug’ term of the ‘my-custom-tax’ taxonomy.
See the WP_Query Codex.
Related Posts:
- Programmatically publish a post (custom post type) with custom fields
- Why are comments and trackbacks still getting through for custom post types?
- Change slug of registered custom post type in child theme
- Why get_next_post_link() or get_previous_post_link() doesn’t return the required links?
- Add Settings to Custom Post Type
- How to set a custom post type post as static front page?
- Custom post type archive with pagination?
- Displaying Post Title on Post Edit page?
- How to save contact form 7 data in Custom Post Types (CPT) [closed]
- Custom user role not working as expected
- Rewrite on custom post type permalink not working?
- Custom post type archive with dynamic taxonomy filtering – is it possible
- Multiple Archive Pages for Custom Post Types AND Taxonomies
- Add common Post Actions to Custom Meta Column
- Custom Taxonomy Breadcrumb Navigation
- Make custom post type display as a page
- Problems excluding a custom post-type from the loop
- Adding menu_order to CPT admin page
- Custom post type with specific category structure
- Is it possible to make tag archive page specific to Custom Post Type?
- get custom post type categories
- reference the current category being used in the category.php page
- Multiple portfolios with one custom post type?
- Custom Post Type not visible on category page
- XML-RPC and Custom Post Types
- How to enable a custom post type to custom user role in WordPress
- How to create an array for a CPT post ID to use in an IF/WHILE statement
- I can’t choose the custom taxonomy in my custom post type on Gutenberg
- Get all Posts If has same custom field values in Posts
- Unable to display list of custom posts
- Retrieve value of a category’s custom field
- WP REST API – reading custom post type
- Rewrite and custom post type: order by custom field not working
- How to make a field appear only if a post meta field has a defined value?
- wp_list_categories() – current-cat class also inside posts?
- WordPress multiple custom post types capability conflict in a single menu
- Adding custom post category slug in permalink causes 404 error for pages and posts
- Taxonomies don’t show up on in the dashboard page for a custom post type in wordpress 5.22
- Changing the search url according to language
- Taxonomies relations
- Adding custom taxonomy in same menu place with two custom post types
- Multiple pages for posts?
- ‘exclude’ argument is not working with get_posts for a custom post type
- How to use Custom Page Templates for hierarchical Custom Post Type
- Multiple templates for single custom post type
- How can i display movies in profile page, added by an user?
- How to get a custom type post data when it has a connection with another custom type post?
- List of child custom post types lists all custom post types
- attach CPT data to a taxonomy
- Full RSS feeds for Custom Post Types
- How to build a WordPress post review system beside commenting
- Where are post type columns stored in database?
- posts within custom post type all share the same content in the front-end
- Custom Post Type with Configurable Sidebar via ACF
- How to get xml file for a single post type?
- How to change single custom post template by custom taxonomy?
- How to query Posts from a custom post type which contains a custom taxonomy?
- Let users upload image(s) to the post from front end
- Insert custom fields to a custom post type
- How to order custom posts by one of the custom fields value, ‘date’?
- Function to allow single post template based on custom taxonomy?
- Multiple custom post types on index page with custom templates
- Custom Post Type, Custom Taxonomy Template: How to get current taxonomy name?
- A sports wordpress website
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- Dynamic template page calling shared taxonomies CPT or Plugin post type : how to clone taxonomy for plugin + set up dynamic shortcode
- How to create additional rendering for custom post types?
- Show a custom post title in another custom post type in Meta box
- Custom Column in CPT admin table not updated after Quick Edit save
- how to display posts content on the custom css popup by clicking on each title on the sidebar?
- 404 – Taxonomy Archive Page
- Convert category to custom post type
- How do I insert a custom post type query after a certain number of recent posts and then resume recent posts?
- Create and Update 2 CPT sequentially
- how to display new private message to users?
- Custom taxonomy with custom post type archive page
- Multiple non-hierarchical custom taxonomies frequently used terms showing up in first selected taxonomy box
- How to seperate posts by categories?
- I want to create pagination for my custom post type archive that i am displaying with loop
- Search in multiple specific post types
- Showing taxonomies with terms that are attached to custom post
- Help with Travel Guide Setup
- custom search form for custom post
- How to set a default CPT template and create post attribute´s display rules?
- Show custom post type under last posts configuration
- Custom post type taxonomy template and URL confusion
- Project Category Heading
- Getting Custom post category from Form
- Optimise custom post type queries
- Loop with Custom Post Type and Taxonomies
- delete custom post type using a submit form
- wp_get_archives(); Change output of link
- Problem with custom post type search
- Allow certain part of a page to be easily updated for client?
- Custom post type – columns order
- Custom taxonomy labels won’t display
- Query custom type posts by array of IDs
- Custom post type with custom taxonomy
- Passing postid of Testimonial Custom Post in Shortcode Parameter
- How to get ‘Products’ on home page?