The post_category
you are using is for core categories taxonomy. For custom taxonomies you have to use tax_input
. For example, the next code set terms for custom_tax_category
and custom_ta_tag
taxonomies.
$args = array(
'post_type' => 'custom_post_type',
'post_title' => wp_strip_all_tags( $title ),
'post_content' => 'some content',
'post_status' => 'publish',
'post_author' => $author_id,
'tax_input' => array(
'custom_tax_category' => array( $category_id ),
'custom_tax_tag' => array( $tag_id )
),
);
$new_cpt_id = wp_insert_post( $args );
Related Posts:
- WP insert post and custom taxonomy
- Not Able to Insert Taxonomy Term Using wp_insert_post()
- wp_insert_post custom taxonomy
- Assign category to front end post
- WordPress tax_input only if logged in
- Programmatically adding posts
- How to checked selected category checkbox when my custom post inserted from frontend
- How do I find out which (page) template file my custom child post is looking for?
- wp_insert_post deleting previous post custom meta
- install.php Custom Taxonomy Term not being added to custom post
- How to Add Custom Taxonomy To Woocommerce Plugin
- How to get the posts of a custom taxonomy term
- How can I rewrite URLs to pass taxonomy and post type values to the query?
- Custom taxonomy not showing up when adding a new custom post type
- query multiple taxonomies
- wp_set_object_terms() is not replacing term, but creating a new one
- Custom Post Type Permalink For Parent/Child, 404 Page Not Found Error
- Create an archive page for custom taxonomies
- Rewrite permalinks for custom posttype and custom taxonomy
- How to check if last uri segment is a custom post type or taxonomy term?
- Categories under custom post types doesn’t show properly
- Hide child term posts on parent term pages
- List all posts in Custom Post Type but group dynamically by Custom Taxonomies
- get a list of posts from Custom Taxonomy
- Want to filter only parent post in admin area
- Custom Meta Boxes – Nonce Issue – Move to trash issue
- Trying to manage templates on a blog with lots of custom taxonomies
- Display custom taxonomy as dropdown list
- Display Custom Category (taxonomy) Name in Custom Post Type
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Query to change custom post type with specific category
- Custom post type and taxonomy permalinks – Structure
- Best action hook to create custom post and assign taxonomy terms to it on plugin activation?
- Custom Post Type and Custom Taxonomy Permalinks
- How many Custom Post Types to register?
- Insert HTML inside link in a walker
- Set menu active state for custom posttype and category, given custom taxonomy term
- How to bulk copy custom fields between custom posts?
- get_attached_media() on author page not working
- Custom post type structure for posts with multiple child posts
- create parent post using wp_insert_post
- Search / Filter posts on Title/Content OR Tags
- Hide parent categories when clicked, and show it’s childs
- Custom taxonomy and custom post type – wrong permalinks and template
- Get unique superset of taxonomy terms from a list of custom posts in another hierarchical taxonomy
- Auto Complete Search
- Custom taxonomy returns 404
- permalink /category/post-name with custom post type and taxonomy
- Displaying Custom Taxonomies From Multiple Custom Post Types
- Display and register custom categories for custom post types
- Pagination Not Working for Custom Taxonomy with Custom Query – 404 Error
- Custom Taxonomy Is Being Pulled into a Page, But It Doesn’t Have A Hyperlink
- Querying two taxonomies with tax_query not woking
- Is it possible to add posts and images (auto resize) for custom post types with a script?
- How to handle this specific case of custom post type?
- Urls in Custom Post Type work for Terms but not for its Taxonomies
- Get custom category ID of current custom post within the loop
- Add filter to Admin list for all custom post types by their custom taxonomies
- Single.php for Custom Post Type > Taxonomy > Term
- Displaying custom taxonomy menu in custom post type archive
- Custom post types templates
- prevent sub categories to show up
- Custom post type category link redirecting to 404 page
- Archive page URL for custom taxonomy and post type
- Custom Post Type Archive Page showing as 404
- Custom taxonomy terms hierarchical navigation
- Is it possible to add the Gutenberg block editor to a custom taxonomy?
- What is the best way to structure posts for the same event happening in different years?
- Dynamically Adding Posts of Post Type to A List
- Multiple Custom Post Type in Taxonomy Archive Causing White Screen
- Adding a Section for Visitors
- Why is my loop not populating the page with my custom taxonomy terms from my custom post type?
- Show parent category and subcategory once in while loop
- I cannot display custom posts in custom taxonomy
- How to change URL structure for custom post type in wordpress? Custom taxonomy + custom Post name [duplicate]
- Remove CPT Slug with 2 taxonomies and 1 post meta
- Custom taxonomy with custom post type template not showing
- One-Time Script TimeOut for Large Data
- CPT Efficient way to display posts from different categories with custom query
- Generate slug and meta data if meta field is empty
- Associate custom categories to different user IDs
- How to create default taxonomy term for a custom post type? [duplicate]
- Extensive search filtering and results->PDF in the front-end
- archive-{custom_post_type}.php not getting recognized wordpress
- How to retrieve the permalink for a specific (custom) term?
- Values inside a custom field to determine which category posts to display
- Taxonomy and Rewrite Structure
- Pagination for a Custom Taxonomy
- Trying to create hierarchy between 3-4 custom post types
- title tag for custom post type remove taxonomy name from title tag
- Create a page selector using taxonomies
- Advanced search form with filters for custom taxonomies and custom fields
- Only One Post of Custom Post Type Appearing on Template Page
- Code to show related posts (custom post type and custom taxonomy/category) is messing with other code
- register_term_meta not working
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- Taxonomy listing issue – does not display how I would like
- Title- Custom taxonomy by using get_term
- Complex Custom Loop with Includes
- How to automatically compare date from custom post type with current date and change taxonomy based on a result?