categories - in post content shortcode works, but hardcoded in same page template doesn't?

So I have a super simple Woocommerce shortcode [product_categories], It's supposed to show product categories from

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 You are missing the "_" in your shortcode. It should be [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
  • @LWS-Mo If [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
  • 1 Yes [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
  • Omg... feeling stupid after the answer is so humiliatingly easy is never getting old for me. Yes, the problem was the lack of underscore for christs sake. To think I have the balls to consider myself a WP developer. – Jussi Commented Oct 28, 2019 at 13:45
  • it was like missing a ; 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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信