While loop shortcode problem

admin2025-06-04  4

I have created a shortcode using the while loop, which is going to break the loop when used with the page builder. How to solve it. Here may custom shortcode here my showing part

I have created a shortcode using the while loop, which is going to break the loop when used with the page builder. How to solve it. Here may custom shortcode here my showing part

Share Improve this question edited Jan 14, 2019 at 9:29 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Jan 14, 2019 at 8:14 RohitRohit 133 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You don't use global $wp_query object anywhere in your code, so there is no point in calling wp_reset_query().

On the other hand, you do use global $post variable, so after your code you should restore it's original value with wp_reset_postdata();.

So change wp_reset_query() to wp_reset_postdata() and it should be OK.

And one more thing...

Shortcodes should return their values and they should not display anything.

So you can't use the_title() inside of it - this template tags echoes its value and doesn't return anything.

You should change it to get_the_title().

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749015276a315633.html

最新回复(0)