$x = wp_insert_term( 'Duper', 'category' );
// $x = array ( 'term_id'=> 692, 'term_taxonomy_id'=> 692 );
The term_id and the term_taxonomy_id always the same?
Which one should I use as a category ID?
Example:
wp_insert_post( array( 'post_category'=> array( $x [ 'term_id' ] ) ) );
// OR
wp_insert_post( array( 'post_category'=> array( $x [ 'term_taxonomy_id' ] ) ) );
Thanks.
]]>Is there a way to make the newly created term appear for the user without having to refresh manually?
]]>Test sample:
wp_insert_term( ‘t’, ‘post_tag’ ); // Inserts new term
wp_insert_term( ‘t’, ‘post_tag’, array( ‘slug’ => ‘t-alternative’ ) ); // Should insert another term too according to API
But in the second call hook ctl_sanitize_title redirects slug to already existed due to $is_term check in the code.
]]>I am bulk inserting terms from a csv file, setting the language with pll_set_term_language() and setting the translations with pll_save_term_translations().
Is there a way to complete my automatic import by forcing the use of a same slug for both languages at the same time? I do not want to have to go through the terms manually, that would be awfully tedious!
Best regards,
Fr
foreach ($mycategories as $mycat){
$myterm = term_exists($mycat->Name, 'product_cat');
if ($myterm !== 0 && $myterm !== null) {
$cat_ID_array = get_term_by( 'name', $cat->Name, 'product_cat');
$cat_ID = $cat_ID_array->term_id;
} else {
$cat_name = $cat->Name;
$catid = wp_insert_term($cat_name, 'product_cat');
<em>$cat_ID = $catid['term_id'];</em>
}
echo '<input type="checkbox" name="prod_category[]" checked value="'.$cat_ID.'" ><label>'.$cat->Name.'</label>';
}
foreach ($subcategories as $subcat){
$subterm = term_exists($subcat->Name, 'product_cat');
if ($subterm !== 0 && $subterm !== null) {
$subcat_ID_array = get_term_by( 'name', $subcat->Name, 'product_cat');
$subcat_ID = $subcat_ID_array->term_id;
} else {
$subcat_name = $subcat->Name;
$subcatid = wp_insert_term($subcat_name, 'product_cat');
$subcat_ID = $subcatid['term_id'];
}
echo '<input type="checkbox" name="prod_category[]" checked value="'.$subcat_ID.'" ><label>'.$subcat->Name.'</label>';
}
I am getting an error on the line = $cat_ID = $catid[‘term_id’];
Fatal error: Cannot use object of type WP_Error as array in…..formsubmission.php on line 226
Can anyone point me in the right direction please ?
]]>I have the following problem:
I have written a plugin which adds a custom post type with a custom toxonomy to my wordpress site. The plugin runs a cronjob every 10 minutes. When the cronjob is executed, data is fetched from a remote server. A part of the data contains terms that have to be associated with my custom post type. So i want to insert them as term in my custom taxonomy for my custom post type.
I tried to use wp_insert_term(), however after calling it nothing seems to be inserted. Did anyone face this problem aswell? and how did you solve it?
Thanks in advance.
]]>I cannot find a way to automaticly update a custom post when it is used in another custom post type.
For example: ‘Man A’ in people post type has no taxonomys. Now i apply ‘Man A’ to a company post type who is under a Boss selection.
I would need ‘Man A’ to automaticly have Boss Taxonomy applied to his original people post type.
My current system is scary in long term as i would have to apply it in company, then manaualy pull profile to then also add the Boss taxonomy. Times that with thousands of entrys and project changing hierarchys…
I already have a drop down menu that pulls all people enteries. I would just need a way to automaticly apply the Taxonomy to the People post type aswell without need of manual editing every time.
I have read up on wp_insert_term but not really clear on how i would apply this to my template.
Thanks in Advance.
]]>I use wp_insert_term
to add new terms into my custom taxonony via code. The problem is that those terms does not show up into taxonomy admin table; however, they are created into wp_terms.
Adding terms works only if I add them via form.
I found this solution delete_option("{$taxonomy}_children");
, but this time all terms are not children ( of course, i tried and it didn’t work )
These relationships are formed, and can be found in the database, but using get_terms doesn’t provide the children UNLESS I create 1 child the old fashioned way in the dashboard.
What happens when I create a term in the dashboard editor that finishes the installation of my taxonomy plugin? And how can I fix it…
]]>First, I’m fairly new to programming, keep that in mind.
I’ve written the function below which is meant to determine if a category exists, and if not create it. In either case we should return the category ID.
function category_check($term){
if (!term_exists($term, "category")) {
$arg = array('description' => ucfirst($term) . ' on Amazon.com', 'parent' => "0");
$term = wp_insert_term(ucfirst($term), "category", $args);
return $i;
}else {
$i = get_cat_id($term);
return $i;
}
}
Basically, I’m looping through a list of words. We look at the database to see if the term already exists, if not we add it, if it does, we return the ID. This will not work for ‘new’ terms on the first pass. It looks like its adding the term, but not returning the ID. If the term does exist, the ID returns as expected.
I’m sure it’s due to the syntax of my function, but haven’t been able to hammer it out.
Any help is appreciated =)
]]>