post_category
is only for Core Categories. Use tax_input
instead:
$new_post = array(
'post_title' => esc_attr(strip_tags($title)),
'post_content' => esc_attr(strip_tags($description)),
'post_type' => 'proiecte',
'post_status' => 'publish',
'tax_input' => array(
'categorie' => array(17,16)
)
);
$post_id = wp_insert_post($new_post);
It may be clearer to other developers, and yourself in the future, if you use something other than categorie
– perhaps projecte_category
– just so it’s clearer you’re using a custom taxonomy and not misspelling Category.
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- Inject post (from specific category) between posts in Loop
- Looking to exclude blog posts from category Previous/Next buttons
- How to display related posts from parent category
- Use template for posts with a particular category grandparent
- Can’t get wp_insert_post to work
- how do I get a specific post from a post with a subcategory in WP
- How to show only subcategories in parent category not parent category?
- Get latest post from all categories except one
- get post id from wp_insert_post for get_template_part
- Displaying list of posts in category page
- Do not duplicate posts with multiple categories in multiple loops
- Loading Posts & Category with Ajax
- Pagination at category doesnt work with same name of page
- How to show categories and date on posts
- Trying to show the category of a post in the post display
- Displaying 3 Category Posts differently
- Unable to get Post Category Name and URL
- Front end post submissions do not get submitted in the category
- Trying to see if page is category or single and displaying title with appropriate heading tag
- Display post of specific category on page
- Display current category title on category page
- Disable Attachment Pages Completely
- How to get year, month and hour in WordPress?
- List all categories but exclude current post category on single post page
- Edit category output
- Print number of post (in reverse)
- Count number of published posts by type
- Different background-image by category
- Get taxonomy terms only of the WP_Query current posts
- Woocommerce – remove product from category
- Get category name from custom loop and echo it once
- How to get 2 or multiple custom post types in wordpress functions.php
- Displaying a button on each post
- Hide post if matches current month and year
- Creating bulk posts with Youtube videos
- Getting a specific post values to another div or modal
- Display post category in foreach loop with category link
- Unreadable pagination
- WP grandchild categories in nested ul li
- Get page that displays all children of taxonomy parent
- Open post-content in archive page in a Modal box with bootstrap
- Dilemma of Populating all the categories in a drop down list
- WP Insert Post and then go to post
- JSON REST API WordPress only showing first 10 categories
- Get all categories post is not in
- Automatically add images to a menu
- Load Posts on Click via Ajax into a DIV
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- Store metakey value as an array
- Only show first image in foreach loop
- Post not populating for custom post type based on category selection
- WordPress upload file size error even after raising php limits
- create front-end users post list by specific category
- Error display post thumbnails for previous and next post
- form $_post action value gets truncated after it passes through two forms
- How to use `wp_insert_post()` and `get_permalink()` functions?
- Showing Subcategory Name/Link Instead of Parent Category
- Wp Query : Order by distance lat,lon
- Remove Custom Post Category In WordPress Slug Using .Htaccess
- remove specificly the last tag in all posts
- get value from get_post_meta then reuse it in another get_post_meta
- WordPress Post Block Element not properly parsed with the_content filter
- Build A Custom SQL Query for WordPress Search
- Get main parent category for post (WordPress/Advanced Custom Fields)
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- How to Send Pingbacks for all Posts in WordPress?
- Display articles with a different template in the home page | Solved |
- How can I check if a post with a particular slug or title exists?
- How can I pass php code as a content while publishing a post
- WordPress sorting posts by date and title using a dropdown
- Category Page Displaying all Pages
- Query on a repeater date (acf)
- Trying to get post ID outside loop on blog page
- Split post or page content in two or more columns
- Enqueue script only on child pages of custom post types
- Attach and retrive multiple pdf files to post or page
- Link to index.php from home.php?
- Hide a specific category title from displaying on site
- Get list of posts from attachment
- Return to the beginning of the results of a for loop
- How to insert text into post based on category – via single.php file
- When working with a post, almost all wp_postmeta are deleted
- Populate Posts based on category selected using AJAX that means without page refresh
- random woocommerce categories are not showing when count enabled?
- How to Retrieve All Category Images on Front-End
- Displaying POST content with HTML tags and all
- Pagination in WP Queries
- Add div after every 4 posts then every 2 posts for a responsive loop
- Can’t put a hyperlink on Featured Post’s Image
- Passed variable gets undefined variable error on insert on next page
- WordPress get_post_meta issue
- Why does WP_Query show only the same post even with different categories and endwhile?
- Is there a way to randomize and connect a background and header image?
- Display pages from specific page template
- dynamically filter by category via sub-menu
- Insert new post for each user infinite loop error
- Get unique post in parent category
- Incomplete term slugs output from a foreach loop with get_the_terms
- How to display the date under the post title?