Articles of wp insert term

does wp_insert_term link the term to a certain post ID?

I’m using wp_insert_termto add a custom taxonomy like this: wp_insert_term( $_POST[‘city’], // the term ‘property-city’, // the taxonomy array( ‘description’=> $_POST[‘city’], ‘slug’ => $_POST[‘city’] ) ); It does the job, but it doesn’t link this term to a certain post ID. Thus, my questions are: what does wp_insert_term do specifically? Does it just insert the […]

Insert terms for custom taxonomy on plugin activation, or each page load (init hook)

Consider a plugin which adds a custom Taxonomy and then fills the taxonomy with a large term hierarchy (tens of hierarchical terms, may become hundreds in specific installations). I understand that register_taxonomy() does not store data in the database, therefore it must be used via the init hook so that the taxonomy is registered on […]

wp_insert_term does not insert description.

I’m using this code. I cannot figure out what the heck is wrong with it? $args = array( ‘description’,”My Desc”, ‘slug’ => “My Slug”, ‘parent’ => 0 ); $result = wp_insert_term(“Term1”, “category”, $args); The result is that term is added, term_taxonomy is added. Slug is added. But the darn description is skipped. wp_terms: term_id name […]

wp_insert_post() does not support variable

I have a problem with the following function as I will pass a variable in wp_insert_term: wp_insert_term( $term, $taxonomy, $args = array() ); It does not work if I do this: wp_insert_term( ‘abc’, $taxonomy, $args ); The code is as following: function insert_city($term) { echo $term; if (!term_exists($term, “property-city”)) { $args = array(‘description’=> ‘There is […]

merging terms programmatically while maintaining the count

This question is all about finding out the best way to handle merging similar terms. Let’s say you have 10 posts tagged as Barack Obama and 20 posts tagged as Obama. and you want to group them all under Barack Obama and get 30 posts for it and get rid of the tag Obama. Surely, […]

Adding predefined terms to a taxonomy

I’m writing a plugin for adding a Custom Post called”Dog”. The core of the plugin is strictly based on this one https://github.com/RescueThemes/Rescue-Animal-Custom-Posts I prefer to add predefined sexes after the plugin activation, I would like to add “Male”, “Female”, “Unapplicable” from the start. So, based on other resources I wrote that in the same .php […]

Get category ID after wp_insert_term

I’m using wp_insert_term to create categories, after the category is created I’d like to get its ID: $cat_id = wp_insert_term($name, ‘category’, array(‘slug’ => $slug) ); …however when I try to print $cat_id I get Array instead of the actual ID. I guess I have to state which part of the array I need, but I […]

wp_insert_term is adding a term that has no name

I’m trying to insert a term for a custom taxonomy and a custom post type in WordPress. The problem I’m running in to is that it successfully inserts a term, and at the right hierarchy level, but the term has no name. The line that inserts the term is: $lasttermarray = wp_insert_term($categoryname, “department”, array( “parent” […]

How to sync to custom taxonomies (tag structure)

I have two taxonomies: “Contributers” and “Narrators.” I want to sync the terms in these two taxonomies identically, so much so that I wish to be able to click on “Edit Term” and see the information (Description, Title, slug, etc.) duplicated in the partnering taxonomy. Right now, I have this (below) which does indeed insert […]

import_id parameter for wp_insert_term to create custom ID for category

Is there an option to create a category with a custom ID, like a custom post ID is created using the parameter import_id? $post = array( ‘post_title’ => ‘whatever’, ‘post_content’ => ‘whatever’, ‘import_id’ => 123 ); wp_insert_post( $post ); What I want to do is create a custom post type using wp_insert_post and will import […]