So I have a super simple Woocommerce shortcode [product_categories], It's supposed to show product categories from the shop.
It does this job perfectly if I put it inside the contents of a page as such: [product_categories].
However, if I put the same thing into the template directly it suddenly returns the first post of current category? What?!
So in my template I have only these two rows:
<?php echo do_shortcode('[product categories]'); // this returns a single product which is wrong and totally weird ?>
<?php the_content(); // this returns the categories as intended ?>
I never knew these two methods have some kind of difference. How can I make the shortcode work with the echo way?
So I have a super simple Woocommerce shortcode [product_categories], It's supposed to show product categories from the shop.
It does this job perfectly if I put it inside the contents of a page as such: [product_categories].
However, if I put the same thing into the template directly it suddenly returns the first post of current category? What?!
So in my template I have only these two rows:
<?php echo do_shortcode('[product categories]'); // this returns a single product which is wrong and totally weird ?>
<?php the_content(); // this returns the categories as intended ?>
I never knew these two methods have some kind of difference. How can I make the shortcode work with the echo way?
Share Improve this question asked Oct 28, 2019 at 13:16 JussiJussi 234 bronze badges 5 |1 Answer
Reset to default 0I was lacking the underscore in [product categories].
<?php echo do_shortcode('[product_categories]'); ?>
Above code with "_" returns the correct answer.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745049867a4608321.html
[product_category]
or[product_categories]
. Please check if this is the problem here. Example from the official WooCommerce shortcode documentation:[product_categories number="0" parent="0"]
– LWS-Mo Commented Oct 28, 2019 at 13:22[product_categories]
is working, it should work here as well, the other stuff are filter / limit parameters. but good point here : "_" jussi if you've copied the code directly from the template file, please recheck if that's the case as you've mentioned that it works but shows only one product. – Arsalan Mithani Commented Oct 28, 2019 at 13:33[product_categories]
is working. But if the shortcode[product categories]
is used, this will show a single product. Because[product]
is just a shortcode to show products. To show the product categories itself[product_categories]
should be used. It seems that @Jussi has just forgot the underscore in his shortcode. – LWS-Mo Commented Oct 28, 2019 at 13:38;
while coding, i recommend you should always copy the shortcode from the available shortcode list to avoid these minor mistakes... – Arsalan Mithani Commented Oct 28, 2019 at 13:53