Skip Navigation

[Résolu] Display only the child taxonomy when using [wpv-post-taxonomy}

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created Il y a 9 années et 9 mois. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 18 réponses, has 3 voix.

Last updated by Adriano Il y a 9 années et 9 mois.

Assisted by: Adriano.

Auteur
Publications
#224559

Hi!

I have a shopping page - I have a custom taxonomy type called products, a child of this is brands and further children are the specific brand names. I would like to Use the [wpv-post-taxonomy] to show only the Brand name for any given product and not have it also say "brands." Is this possible?
Thanks!!

#224615

Hi jamesG-3,

Could you describe more details for the question?
Are we talking about this case:
posts 1
--terms under products taxonomy: Brand a, Brand b
posts 2
-- none terms under products taxonomy

You are going to display as this:
posts 1, brands: Brand a, Brand b
posts 2, brands:

#224870

Thanks for the reply. The exactly as you stated. Where it falls down now is the taxonomy is as follows under the product categories custom taxonomy:

Brand
brand 1
brand 2
Men's Clothing
shorts
jeans
etc...

I would like then only to display in the main view

"Product Name"
"Brand 1"

And not display anything except a child of brands. Does that make sense? Presently it would display:

"Product Name"
"Brand 1, Jeans"

#225177

Dear James,

Luo is unavailable to handle this ticket for now, I will take care for you. Our native shortcode doesn't cover this needed, you will need to write a new one. I have one for you, put it in functions.php of the current theme:

function show_child_cat_func( $atts ) {
    extract( shortcode_atts( array(
        'taxonomy' => ''
    ), $atts ) );
  
$args=array(
  'orderby' => 'id',
  'order' => 'ASC',
  'taxonomy' => $taxonomy,
  'hide_empty' => 0,
  );

$categories=get_categories($args);

echo '<ul>';

	foreach($categories as $category) { 
		if($category->parent!=0)
		{
		echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . $category->name. '" ' . '>' . $category->name.'</a> </li> ';
		}
	}
echo '</ul>';     
}
add_shortcode( 'show_child_cat', 'show_child_cat_func' );

You can style this as you want, I used

    to wrap them. You must call this shortcode like this: [show_child_cat taxonomy = "products"]

    Please let me know if you are satisfied with my answer and if I can help you with any other related question.

#225779

Thank you so much for the time and effort with this!

To clarify, the shortcake to bring up all product categories is: [wpv-post-taxonomy type="shop-categories" separator=" " format="link" show="name" order="asc"]

Brands is one of the categories and it has children. It is only the children of brands I want showing. I tried [show_child_cat taxonomy = "products"] and [show_child_cat taxonomy = "brands"] and neither returned a result. What would you suggest?

Thanks again!

#226189

Dear James,

I would like to see your site to understand if this shortcode will works well for you. Can you provide credentials to your site? The private area is enabled, please fill required fields.

#226566

Dear James,

Please use the private area to provide these kind of information, I've just deleted the other reply of you. Also fill the website URL field, I will need it as well.

#226685

They are now in the private section, thanks!

#227118

Dear James,

I've just created an example page: hidden link

I used my shortcode to display child taxonomies of "category": [show_child_cat taxonomy = "category"]

It is working fine. What is the problem?

#227255

Hi there - the list I can show fine. What I am looking to do is to have a shortcode that only displays the child taxonomies selected by the current post. What I mean by this is presently on a product page, as someone adds a project they choose the brand, and they also choose tags. I would like the displayed page to show the brand name that was chosen, but not also show the word "brands" which would be the parent taxonomy. Thanks!

#227307

Dear James,

I see, so the custom shortcode will be another one. Try this below:

function show_child_cat_func( $atts ) {
    extract( shortcode_atts( array(
        'taxonomy' => ''
    ), $atts ) );
   
$args=array(
  'orderby' => 'id',
  'order' => 'ASC',
  'hide_empty' => 0,
  );
 
$categories=wp_get_post_terms(get_the_ID(), $taxonomy, $args);
 
echo '<ul>';
 
    foreach($categories as $category) { 
        if($category->parent!=0)
        {
        echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . $category->name. '" ' . '>' . $category->name.'</a> </li> ';
        }
    }
echo '</ul>';     
}
add_shortcode( 'show_child_cat', 'show_child_cat_func' );

Call the shortcode in the same way and let me know if it solves your issue.

#227338

Hi there - thanks again!

I think I still may be missing something? It still brings back no response to me using the shortcode [show_child_cat] or [show_child_cat_func] - thanks so much for working through this

#227526

Dear James,

I've just fixed it for you. The right code should be:

function show_child_cat_func( $atts ) {
    extract( shortcode_atts( array(
        'taxonomy' => ''
    ), $atts ) );
    
$args=array(
  'orderby' => 'id',
  'order' => 'ASC',
  'hide_empty' => 0,
  );
  
$categories=wp_get_post_terms(get_the_ID(), $taxonomy);

$content = '';
  
$content .= '<ul>';
  
    foreach($categories as $category) { 
        if($category->parent!=0)
        {
        $content .= '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . $category->name. '" ' . '>' . $category->name.'</a> </li> ';
        }
    }
$content .= '</ul>';

return $content;
}
add_shortcode( 'show_child_cat', 'show_child_cat_func' );

Sorry for my mistake, the correct is "return" instead of "echo".

Please let me know if you are satisfied with my answer and if I can help you with any other related question.

#227764

Thank you for further working through this. It is still not returning a response however. [show_child_cat] is coming up blank and [show_child_cat_func] brings up simply the text "[show_child_cat_func]" as written.

Again, thanks for the support!

#227953

Dear James,

It is working fine for me, please look: hidden link

I've just used - [show_child_cat taxonomy="category"] - it is displaying only child categories of this product. If it is not what you want, please explain it a bit more, I'm not sure if understand properly what you want to achieve.

Le forum ‘Types Community Support’ est fermé à de nouveaux sujets et réponses.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.