We’re trying to use your plugin to add a custom taxonomy to our users. But after adding the taxonomy and assigning users to the taxonomy terms, the count always shows 0…
What could be the problem?
Taxonomy code:
register_taxonomy('profession', 'user', array(
'public' =>true,
'single_value' => false,
'show_admin_column' => true,
'labels' =>array(
'name' =>'Professions',
'singular_name' =>'Specialisme',
'menu_name' =>'Specialismes',
'search_items' =>'Search Professions',
'popular_items' =>'Popular Professions',
'all_items' =>'All Professions',
'edit_item' =>'Edit Profession',
'update_item' =>'Update Profession',
'add_new_item' =>'Add New Profession',
'new_item_name' =>'New Profession Name',
'separate_items_with_commas'=>'Separate professions with commas',
'add_or_remove_items' =>'Add or remove professions',
'choose_from_most_used' =>'Choose from the most popular professions',
),
'rewrite' =>array(
'with_front' =>true,
'slug' =>'author/profession',
),
'capabilities' => array(
'manage_terms' =>'edit_users',
'edit_terms' =>'edit_users',
'delete_terms' =>'edit_users',
'assign_terms' =>'read',
),
));
When using the below code or viewing the taxonomy in the admin dashboard, it always shows 0 under count…
$terms = get_terms(array(
'taxonomy' => 'profession',
'hide_empty' => false
));
foreach ($terms as $terms) {
echo $terms->name . ": ";
echo $terms->count. "<br>";
}
]]>echo get_the_term_list( $user->ID, 'service', '<p><span class="label">Services:</span><span class="data">', ', ', '</span></p>' );
or
$terms = get_the_terms( $user->ID, 'service' );
if( ! empty( $terms ) ) :
foreach( $terms as $term ) : ?>
<div class="<?php echo $term->slug; ?>"><?php echo $term->description; ?></div
<?php endforeach;
endif;
]]>
<?php
add_action( 'init', 'authors' );
function authors() {
$labels = array(
'name' => 'Authors',
'singular_name' => 'Author',
'menu_name' => 'Authors',
'all_items' => 'All Authors',
'parent_item' => 'Parent Author',
'parent_item_colon' => 'Parent Author:',
'new_item_name' => 'New Author Name',
'add_new_item' => 'Add New Author',
'edit_item' => 'Edit Author',
'update_item' => 'Update Author',
'separate_items_with_commas' => 'Separate Authors with commas',
'search_items' => 'Search Authors',
'add_or_remove_items' => 'Add or remove Authors',
'choose_from_most_used' => 'Choose from the most used Authors',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'item', 'product', $args );
register_taxonomy_for_object_type( 'item', 'product' );
}
?>
But I can’t seem to pull any of this through to the product page, where I want to display the author’s name. I’ve been trying to use the <?php echo get_the_terms( $name, $authors ); ?>
hooked to woocommerce_single_product_summary
in an attempt to get at least some data to display, but debug keeps throwing up Undefined variable
errors.
Chances are, I’m missing something rather basic, but all the same, I’d really appreciate some help.
Thanks, Josh
]]>Help Centre > Parent > Child
There are four parent categories and several child categories in each parent.
I am using the following:
$terms = get_the_terms($post->ID, 'help-centre-category');
echo '<ul class="breadcrumb">';
echo '<li><a href="'.get_site_url().'/help-centre/">Help Centre</a></li>';
echo '<li><a href="'.get_site_url().'/help-centre/'.$terms[0]->slug.'/">'.$terms[0]->name.'</a></li>';
echo '<li><a href="'.get_site_url().'/help-centre/'.$terms[0]->slug.'/'.$terms[1]->slug.'/">'.$terms[1]->name.'</a></li>';
echo '</ul>';
My understanding was that $terms[0] was the parent and $terms[1] was the child, however this only seems to be the case for posts in two of the four parent categories, whilst the other two parent categories are generating the breadcrumb backwards, ie:
Help Centre > Child > Parent.
Am I approaching this incorrectly?
]]>function get_rug_terms_name($term) {
$terms = get_the_terms( get_the_ID(), $term);
if( !empty($terms) ) {
return implode(", ", array_map(function(WP_Term $term){
return $term->name;
}, $terms));
}
}
function get_rug_terms_slug($term) {
$terms = get_the_terms( get_the_ID(), $term);
if( !empty($terms) ) {
return implode(", ", array_map(function(WP_Term $term){
return $term->slug;
}, $terms));
}
}
I was thinking something like:
function get_rug_terms($term, $which_term)
and then return $term->$which_term;
but that doesn’t seem to work. Feel like i am probably close, but just not quite getting it.
Any help would be great!!!
]]>while ($query4->have_posts() ) : $query4->the_post();
if( has_term('' , 'orderIt1' )) {
$theIDforordering2 = get_the_ID();
$firstRandArray = get_the_terms( $theIDforordering2, orderIt1 );
$secondRandArray = get_the_terms( $theIDforordering2, orderIt2 );
var_dump ($firstRandArray);
var_dump ($firstRandArray['"name"']);
} else {echo "";}
When I do var_dump for the $firstRand it comes back with this:
array(1) { [0]=> object(WP_Term)#3105 (11) { [“term_id”]=> int(32) [“name”]=> string(1) “1” [“slug”]=> string(1) “1” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(32) [“taxonomy”]=> string(8) “orderIt1” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(1) [“filter”]=> string(3) “raw” [“object_id”]=> int(188) } }
The custom tag for this post is “1”. So I guess it is under “name”. How do I access that and strip off the string(1) and the quotation marks?
I thought I might get it with $firstRandArray[‘”name”‘] or $firstRandArray[‘name’] or $firstRandArray->name but all return NULL.
]]><div class="work-pager cycle-pager">
<?php foreach((get_the_terms($post->ID, 'work_category')) as $currentterm) {}
$args = array (
'post_type' => 'work',
'tax_query' => array(
array(
'taxonomy' => 'work_category',
'field' => 'term_id',
'terms' => $currentterm,
),
),
);
$work_nav_query = new WP_Query( $args );
$current_post_ID = $post->ID;
if ( $work_nav_query->have_posts() ) {
while ( $work_nav_query->have_posts() ) {
$work_nav_query->the_post();
$class = get_the_ID($work_nav_query) == $current_post_ID ? 'cycle-pager-active' : '' ; ?>
<span class="<?php echo $class . $currentterm->ID; ?>"><a href="<?php echo get_the_permalink(); ?>" title="<?php echo get_the_title(); ?>">?</a></span>
<?php }
}
wp_reset_postdata(); ?>
]]>I have developed a plugin for a client and during my testing, I found myself surprised to find that both taxonomies “product_cat” and “product_tag” are returning invalid when using the function get_the_terms().
Any other taxonomy I test with returns OK.
This function is required in order for the plugin to work.
Any chance you can find out why this is?
I am using the latest WordPress and WooCommerce.
I look forward to your response.
Thank you.
https://www.ads-software.com/plugins/woocommerce/
]]>I have this code right now, and it’s not working. Can anyone see what’s wrong with it? The slug of the custom taxonomy is ‘ras’.
<?php
$rassen = get_the_terms( $post->ID, 'ras');
if ($rassen) {
foreach ( $rassen as $ras ) {
echo "<p>van het ras / soort</p>";
echo "<h3 class=\"ras\">";
echo '<a href="'.get_term_link($ras).'">'.$ras->name.'</a>';
echo "</h3>";
}
}
?>
I also replaced get_the_terms with wp_get_object_terms, with no effect.
]]>The following code displays category linked to subcategories. The problem is that only one subcategory is shown despite several are available.
How can I modify this code so more subcategories($val) are shown on the page?
add_filter("woocommerce_product_tabs", "custom_tabs");
function custom_tabs( $_original )
{
global $post;
$aTerms = get_the_terms($post->ID, "product_cat");
$aUse = array();
foreach( $aTerms as $oTerm )
{
if( $oTerm->parent > 0 )
{
$oParent = $aTerms[$oTerm->parent];
if( empty($oParent) )
{
$oParent = get_term_by("id", $oTerm->parent, "product_cat");
}
// Original line
$aUse[$oParent->name] = $oTerm->name;
}
}
echo "<div class='specifications'>";
foreach( $aUse as $cat => $val )
{
?>
<div class="spec-wrapper">
<div class="type">
<?php echo $cat; ?>:
</div>
<div class="value">
<?php echo $val; ?>
</div>
</div>
<?php
}
echo "</div>";
return $_original;
}
This is the page:
https://www.legrandcru.nl/product/soave-classico-azienda-agricola-fornaro-2013/
Serveertip is a category and Vis gestoofd is a subcategory, but there are more subcategories but they don’t show up.
Alot of thanks in advance for your time, hope you can help me out.
Greetings,
Mickey
]]>