【问题标题】:need to add all post ids to query_posts()需要将所有帖子 ID 添加到 query_posts()
【发布时间】:2013-03-04 08:49:29
【问题描述】:

我需要在 query_posts() 中获取与特定类别相关的所有帖子 ID。

我目前正在使用以下代码:

<?php
query_posts('cat=11&p=-1');
while ((have_posts()) : the_post();
the_title();
the_content();
endwhile;
?>

我希望在“p=”中插入 -1 会带来所有帖子,但事实并非如此。 有人可以帮忙吗?

提前致谢, 埃亚尔

【问题讨论】:

  • 需要更多代码,id是在同一个表还是不同的表?

标签: php wordpress post


【解决方案1】:

我只是希望你的实际代码不包含这个不平衡的括号 @while ((have_posts())) : the_post();

根据:http://codex.wordpress.org/Class_Reference/WP_Query#Parameters $query = new WP_Query('p=7');

这意味着我们需要显示 id=7 的帖子。

现在根据您的代码: query_posts('cat=11&p=-1');

这意味着,显示类别 id =7 且 id=-1 的那些帖子,这对我来说看起来不是很有用。

在我的情况下: query_posts('cat=11'),以及 query_posts('cat=11&posts_per_page=-1') 工作顺利。

现在你想告诉你这个插件是如何依赖“p”的,所以我们可以找到一个替代的解决方案。

【讨论】:

    【解决方案2】:

    引用Wordpress Functin Reference:检索

    一个类别中的所有帖子。中的“博客页面最多显示”参数 设置 > 阅读会影响您的结果。为了克服这个问题,添加 'posts_per_page' 参数。例如:

    query_posts( array ( 'category_name' => 'my-category-slug', 'posts_per_page' => -1 ) );
    

    这将返回该类别中的所有帖子。

    【讨论】:

    • 不工作 :-( 我必须在查询中有“p”,因为有一个插件使用它。
    • @EyalBinehaker 然后试试query_posts('cat=11&amp;posts_per_page=-1');
    猜你喜欢
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多