Just pass array with category terms in wp_set_post_terms taxonomy parameter.
global $post;
$post_id = $post->ID;//get the current post id
$terms = array('term1','term2');
$taxonomy = 'category';
$append = false; // or true
wp_set_post_terms( $post_id, $terms, $taxonomy, $append );
Related Posts:
- Get custom post type by category in a page template
- Query posts by custom post type and custom taxonomy
- How to get only one category of custom post type?
- Weird problem happening with custom taxonmy when creating/updating posts
- Conditional Query of Custom Post Type and custom taxonomy
- Control content before and after custom post type loop
- attach CPT data to a taxonomy
- Creating a non-hierarchical Taxonomy that behaves like categories
- Displaying One Custom Post Type’s Content On Single Post of Another Custom Post Type
- Query Multiple Custom Post Types & Exclude a Taxonomy Term
- How do I ensure that post_type and Taxonomy use the same slug?
- WordPress query posts by custom post type not workng
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- what is the correct way to compare dates in a WP query_posts meta_query
- Display a query with multiple post types and same relationship on a single page
- WordPress Custom Post Types with a page as a parent?
- Get Custom Taxonomy ID within loop
- Custom Taxonomy with Custom Post Type Finds No Posts
- TV Show database – Best way for structuring it?
- Correct way to use a form to to filter custom posts by taxonomy terms?
- how to group custom post type posts by custom taxonomy terms
- Showing current taxonomy terms
- Categories under custom post types doesn’t show properly
- automatically create taxonomy with same name as post title
- Query post types with multiple keys
- pre get posts changing the query
- After deleting a post are terms, and custom meta deleted?
- Get all posts WHERE custom_field is LIKE value
- Show ACF field from custom taxonomy and display on the single template
- ‘category__and’ for custom taxonomy?
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Programmatically adding posts
- Keep main articles and author blogs seprerate, News / Magazine like site
- removing custom tax & CPT slug, adding taxonomy term in front of custom type
- Order WordPress Custom Taxonomy Pages & Pagination Not Working
- Show Two custom Post type and their posts on category page
- How to create an advanced filter search?
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- how can i get posts from custom post type particular taxonomy category
- Setting posts per page in query_posts
- How to insert content from another Custom Post type into Post?
- Get rewrite slug of custom post type in template
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- How to customize a permalink (URL) structure?
- Archive for custom taxonomy lists all posts instead of current taxonomy
- will post_id ever change? Can I safely use post_id for custom queries?
- List custom taxonomy specific to one custom post type
- Custom Post Type Query for Sidebar Doesn’t Work on Front Page
- 404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
- Why are taxonomy terms not saving when using custom meta boxes with radio button taxonomy selectors?
- Hide parent categories when clicked, and show it’s childs
- How to produce a sub-page-system in WordPress
- Custom query – get_the_terms not work
- Display custom posts randomly in custom taxonomy archive
- Targeting custom post type via functions.php doesn’t work
- Different options per post type in WP_Query
- When I choose category from dropdown then everything working fine.But in backend it checked only child not parent [closed]
- get_terms() returns Trying to get property of non-object error for custom taxonomy
- Foreach loop returning more than one item when querying taxonomy
- Function to erase every post from a taxonomy
- Compare Two Custom Post Types Using The Same Custom Taxonomy
- Get terms for a specfic post from multiple taxonomies in custom post type
- Using page title as a link to term archive
- Is it possible to have hierarchical taxonomy and hierarchical custom post types in one permalink?
- Custom taxonomy not saving correctly
- Setup page template array in a custom post type
- Sorting the Loop by Taxonomy Value
- Custom post type page with parameter
- How to get post count of specific taxonomy that have store name & category
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- 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 and a “sticky” position taxonomy
- custom post type and user post count shortcode
- pagination problem listing custom post types of taxonomy in wordpress
- Filter Custom Post Type Posts by Taxonomy
- Change Search display for Custom Post Type
- Show parent category and subcategory once in while loop
- Custom search for a custom post type in WordPress
- CPT: multiple loops with different terms
- Stored meta from attachment, video length?
- tax_query not working?
- Add active class to foundation 6 tabs while looping categories
- Help with Travel Guide Setup
- Show custom taxonomy not in submenu
- Getting a 404 on single custom post type page when using rewrite on a custom taxonomy
- Pods pagination erases my sub menu
- How to Fix WordPress 500 Internal server error due to custom post type
- Display 2nd category, only once, as sub-heading, in the loop
- Values inside a custom field to determine which category posts to display
- Exclude Custom Post Type from shared Custom Taxonomy
- Sort by Custom Post Type (Multiple Loop)
- WordPress Custom Post Type and sort by Tags
- Get link for feed of specific post type AND taxonomy
- Looping taxonomy in taxonomy?
- posting twice from an array?
- Custom Loop for custom post type. Compare by meta_value?
- cannot export data from CPT UI (books)
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working