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
- Automatically add custom CSS to new posts using a category template
- How Display Posts on category
- Hide wordpress field if data is empty in post!
- How can I use wp_query to show all product data using just the products ID?
- hover image appears below placeholder instead of overlayed
- combine Code 1 with Code 2
- Query all posts of a custom taxonomy term
- get current product name in functions.php
- Retrieving Author ID in wp-admin area
- get post based on category chosen in drop down – The ajax method
- How to use transient in this code for related post?
- Getting a specific post values to another div or modal
- Trying to add attribute to my posts’ featured image
- Creating a related post section based on similar categories
- Swapping wp_dropdown_categories function with wp_category_checklist
- Displaying the last post on static homepage
- Why not yield/iterable in posts interface?
- Best practice for migration friendly images in posts/pages?
- Proper syntax or method for keeping url in modified isotope / category links
- Display post category in foreach loop with category link
- How to show part of the_content?
- Filter Select results based on selection
- What is an equivalent of single_cat_title for getting the slug of the category?
- Unreadable pagination
- 200 Rewrite blog post links
- Issue adding sub category programmatically
- How to set a min number of words for a blog post
- Loop through categories and display posts title under each dropdown
- Get post id in a function when edit/add a post
- How to exclude category ID from Looper in WordPress
- Add a specific part of current category page url to shortcode
- Automatically create child pages and grandchild pages when saving a (parent) page
- WP grandchild categories in nested ul li
- Grab posts by multiple categories
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to show single category archive
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Move category description below post list in blog
- How to pick the default selected value in wordpress dropdown?
- Second transition_post_status hook fired instead of the first
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Auto-Select Parent Category as Primary
- Get page that displays all children of taxonomy parent
- How to store post ID’s in cookie or session to display the same posts later
- Which hook/action will help me solve my problem?
- How can I add extra word in permalink when someone click download button?
- Don’t insert if permalink is the same?
- selected option if current category is the value
- Post + form + action + results on the same page
- Open post-content in archive page in a Modal box with bootstrap
- get_template_part based upon post’s category
- how to save selected option in variable for rest api category filter
- Setting default category base on theme activation
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Hide subcategories (widget)
- Alert Bar section within WP loop is displaying even though there are no posts
- Let Users Choose Post Categories
- remove post that has no content
- Different post styles depending on category
- Display category name only once inside loop
- Loading index.php contents which located outside blog folder for post single page
- get post content of particular post by url
- Post repeating with infinite scroll
- Custom posts in different columns style
- Get children post mime type using parent post_ID wp_post
- Use of wp_insert_post and parameters
- Creating a post from data returned from HTML form
- Getting error when using wp_insert_post()
- 404 error when I acess the second page of post-type
- how to show only specific category for a template
- Redirect to another page using contact form 7? [closed]
- Display post category in foreach loop
- Dilemma of Populating all the categories in a drop down list
- Which PHP page is the Default Posts Page
- Display most popular posts of category
- retrieve post data and insert it in seperate static html page without WordPress
- Creating sub-categories via php
- post category in wp_insert_post
- Define specific category name in PHP