为什么我的have_posts陷入无限循环?
3 个回答
- 投票数
-
- 2011-11-20
看看这个答案:按标签获取自定义帖子类型
我相信您会在
$flagged_stores->the_post()
循环内使用while
.Look at this answer: get custom post type by tag
I believe you'd use
$flagged_stores->the_post()
insidewhile
loop.-
+1-被发现;它确实应该显示为:` have_posts()):$flagged_stores->the_post();?>`-@yuval:无限循环是否总是显示相同的标题?+1 - well spotted; it should indeed read: `have_posts()): $flagged_stores->the_post(); ?>` - @yuval: did the endless loop always show the same title?
- 0
- 2011-11-20
- Michael
-
@Michael是的,因为没有[`the_post()`](http://codex.wordpress.org/Function_Reference/the_post),您就不会逐个查找帖子@Michael yes, because you don't seek post by post without [`the_post()`](http://codex.wordpress.org/Function_Reference/the_post)
- 1
- 2011-11-21
- brownian
-
也不要执行"echothe_title()",只是"the_title()",因为它默认情况下会自行打印.通常,您将`echo`与以get_开头的函数一起使用,例如在`echoget_the_title()`中Also don't do `echo the_title()` it's just `the_title()`, as it prints itself by default. Usually you use `echo` with functions starting with get_, like in `echo get_the_title()`
- 0
- 2015-08-28
- aesede
-
- 2011-11-20
尝试并使用
'posts_per_page'
而不是'limit'
- http://codex.wordpress.org/Class_Reference/WP_Query#Parameterstry and use
'posts_per_page'
instead of'limit'
- http://codex.wordpress.org/Class_Reference/WP_Query#Parameters-
仍然没有运气.还有其他想法吗?谢谢!Still no luck. Any other ideas? Thanks!
- 0
- 2011-11-20
- yuval
-
- 2011-11-20
我不知道这是引起无限循环的原因,但是您的WP_Query已关闭.
$flagged_stores = new WP_Query( array ( 'post_type' => 'store', 'orderby' => 'ID', 'meta_key' => 'flagged', 'posts_per_page' => 10 ) );
我更新了
'orderby'
和'posts_per_page'
.I do not know if this is what caused the infinite loop, but your WP_Query is off.
$flagged_stores = new WP_Query( array ( 'post_type' => 'store', 'orderby' => 'ID', 'meta_key' => 'flagged', 'posts_per_page' => 10 ) );
I updated
'orderby'
and'posts_per_page'
.
我有以下代码,由于某种原因,该代码会导致无限循环.有人可以解释发生了什么吗?
谢谢!