0

I have to display custom taxonomy for every product which is i have selected for every product from back end.

I have created custom taxonomy city in that custom taxonomy i have added the Nashik ,Mumbai city.

In product page i have assigned custom taxonomy city Nashik to that product that assigned city Nashik i have to display at product page.

i have tried out with bellow code but it's displaying the all city list like Mumbai Nashik here i have to display specific city name for product.

wp_tag_cloud( array( 'taxonomy' => 'city', format => 'list' ) );

3 Answers 3

1

Instead of using wp_tag_cloud pls try this in product page

<?php $terms = get_the_terms( $post->ID , 'city' ); 
                    foreach ( $terms as $term ) {
                        $term_link = get_term_link( $term, 'city' );
                        if( is_wp_error( $term_link ) )
                        continue;
                    echo '<a href="' . $term_link . '">' . $term->name . '</a>';
                    } 
                ?>
0

It might be a bit late already but I think the Woocommerce - Products By Custom Tax plugin should do what are you trying to achieve, I am the developer.

For your case the shortcode of the plugin would be like this:

[woo_products_custom_tax tax_name="city" tax_tags="nashik" columns="4"]

If you want to show more cities you can place them separated by a comma on the tax_tags attribute

[woo_products_custom_tax tax_name="city" tax_tags="nashik,mumbai" columns="4"]
1
  • All ready got the right answer. Apr 3, 2015 at 4:13
0

Once you have created custom taxonomies in WordPress, the next step is to display them on post pages. Fortunately, this is a matter of adding the following single line of code to the single.php (located in the theme folder):

<?php the_terms( $post->ID, ‘topics’, ‘Topics: ‘, ‘, ‘, ‘ ‘ ); ?>

By default custom taxonomies use the archive.php template to display posts. However, you can create a custom archive display for custom taxonomies by creating taxonomy-{taxonomy-slug}.php,where taxonomy-slug refers to slug of custom taxonomy.

I found the solution at https://www.wpblog.com/create-custom-taxonomies-in-wordpress/

Hope it will help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.