Articles of wp insert term

Handling duplicates with wp_insert_term()

I’m using wp_insert_term which works quite well Now I want some error handler for when using the same name. $term_id = wp_insert_term( $term, ‘wpsc_product_category’, $args ); if($term_id) {//my operations here} where $term = $_POST[‘categoryTitle’]; I want to display some error when such name already exists. In wp_insert_term, how to check if this $term_id is duplicate? […]

Programmatically create product category and add thumbnail in woocommerce

I’m trying to create product-(sub)categories on a WordPress installation. The (sub)categories part is no problem at all, but I can’t seem to find a way to add the thumbnail image to the specific category. In wp-admin, the field I want to fill asks for an attachment ID, so I tried uploading the image as attachment, […]

how is it possible that using wp_insert_category throw a fatal error?

how is it possible that using wp_insert_category throw a fatal error ? I am using it as explained : with no change except: $cat_defaults = array( ‘cat_name’ => ‘some_name’, ‘category_description’ => ‘as asdfasdf sdf adfa fas f’, ‘category_nicename’ => ”, ‘category_parent’ => ”, ‘taxonomy’ => ‘category’ ); $someSome = wp_insert_category($cat_defaults); i dont know if […]

Programmatically insert hierarchical terms & set terms for post causes glitch?

This question already has an answer here: Inserting terms in an Hierarchical Taxonomy 5 answers

Allow only 1 instance of each term in each custom taxonomy

I’m looking for a function that restricts the creation of each term to only 1 instance within each custom taxonomy. Each custom taxonomy may have the same term but the term may only occur once in each different custom taxonomy. I’m guessing this will need a function for each custom taxonomy.

Creating a non-removable taxonomy term

Is there a way, without modifying the core, to create a term for a custom taxonomy programmatically that is non deletable? “Uncategorized” is an example, but in my case, it does not have to be the default term if a post is not attached a term, but yes it will be a default always existing […]

How to add terms to taxonomy with wp_insert_terms?

I have a huge excel database of locations which I want to add as terms to my current taxonomy. However, I don’t know the best way to do this, as inserting manually could take weeks. I have looked at: but not sure how to use it correctly. My Taxonomy is called: location I would […]

Insert new term during new post creation

i am currently working on a snippet to insert a new post dynamically (it’s a custom post type). During this new post creation i need to insert terms in custom taxonomies associated to the custom post type. I am having the famous “invalid taxonomy” error message and i don’t know how to solve this. Here […]

wp_insert_term doesn't work with custom post type's taxonomy

Here is the problem I am having: I have a custom post type called “weddingguests” This custom post type “weddingguests” has a custom taxonomy, “friendsof”, hierarchic I want to programmatically insert into this custom taxonomy “friendsof” 2 terms: “Friends of the Bride” and “Friends of the Groom” Here is the function and the action I […]

wp set object terms vs wp set post terms

Examining the following sample code snippet from the WP codex, $post = array( ‘ID’ => [ <post id> ] //Are you updating an existing post? ‘post_author’ => [ <user ID> ] //The user ID number of the author. ‘post_category’ => [ array(<category id>, <…>) ] //Add some categories. ‘post_content’ => [ <the text of the […]