term_exists(‘artist’), has_term(‘artist’), is_tax(‘artist’) and is_category(‘artist’) don’t seem to do the trick. I’m 100% certain that the taxonomy is “artist”.
Must be missing something obvious? Thanks in advance for any help!
<?php if ( is_page() ) {
do something
} elseif ( is_tax('artist') ) {
]]>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 ?
]]>The structure of categories:
Category
– Titleist
code:
$ term = term_exists (‘Titleist’, $ taxonomy, 0);
echo print_r ($ term);
answer:
Array
(
[term_id] => 1204
[term_taxonomy_id] => 1204
)
Answer should be NULL!
Am I doing something wrong? How can I search only for the parent category?
Thank!
term_exists( 'my_term', 'category', 0 );
argument 0 is interpreted as no parent argument, so wordpress looks for my_term everywhere not only in terms with 0 parent.
]]>When I try to add the code to a taxonomy, I get an error saying that:
Error: term_exists is not defined
It comes from this if statement in the script:
// Add Code to taxonomy
if (term_exists(code, wheel_type)) {
alert(code);
}
else
{
wp_insert_term(code, wheel_type);
}
Can anyone tell me what I did wrong, or how to add a term to a taxonomy from with in a Javascript section?
]]>Now, I want to add that tire code to the wheel_type taxonomy.
The below code ran great, until I added the if statement under //Add code to Taxonomy
Now nothing is working, but I get nothing in the error console.
I figure it must be a stupid syntax mistake – can anyone help me out?
Or am I missing something else?
jQuery('#replace').click(function(){
//get tire code and name
var code = jQuery('input[name="tire_code"]').val();
var name = jQuery('input[name="tire_name"]').val();
var bname = jQuery('input[name="tire_bname"]').val();
alert(code + " + " + name + " + " + bname);
//get tire brand
var tirebran = jQuery('#tire_brandchecklist').find(":checked").parent('label').text();
tirebran = jQuery.trim( tirebran );
//Add code to Taxonomy
if( term_exists( code, wheel_type ){
continue;
}
else
{
wp_insert_term( code, wheel_type );
}
//update title
var title = code + ' : ' + name + ' tires';
if(tirebran!=''){
title += ' with ' + bname + ' letters';
}
jQuery('input[name="post_title"]').focus().val(title);
});
//-->
</script>
]]>I have tried everything I could find, and the only one that has worked at all is “term_exists”.
However, it is not just calling header2 into this category, but into ALL categories of this custom post type.
<?php if (term_exists( 71 )) {
get_header('header2');
} else {
session_start(); get_header();
}?>
This seems like it would be a simple fix, but I have killed hours upon hours on this. Any suggestions?
]]>