Wordpress query_posts结果与wp_query请求结果不同

时间:2013-11-28 10:13:56

标签: php mysql wordpress

我有一个多站点Wordpress设置(3.5.1,我无法冒险更新),我在切换到正确的博客后查询了一些帖子。

我有一个带有以下参数的query_posts函数:

$posts = query_posts('posts_per_page=5&paged=1&post_status=publish&orderby=date&order=desc');

从查询帖子中查询__变成了{$GLOBALS['wp_query']->query_vars):

Array (
    [posts_per_page] => 5 
    [paged] => 1 
    [post_status] => publish 
    [orderby] => date 
    [order] => desc 
    [error] => [m] => 0 
    [p] => 0 
    [post_parent] =>  
    [subpost] =>  
    [subpost_id] =>  
    [attachment] =>  
    [attachment_id] => 0  
    [name] =>  
    [static] =>  
    [pagename] =>  
    [page_id] => 0  
    [second] =>  
    [minute] =>  
    [hour] =>  
    [day] => 0  
    [monthnum] => 0  
    [year] => 0  
    [w] => 0  
    [category_name] =>  
    [tag] =>  
    [cat] =>  
    [tag_id] =>  
    [author_name] =>  
    [feed] =>  
    [tb] =>  
    [comments_popup] =>  
    [meta_key] =>  
    [meta_value] =>  
    [preview] =>  
    [s] =>  
    [sentence] =>  
    [fields] =>  
    [menu_order] =>  
    [category__in] => Array ( )  
    [category__not_in] => Array ( )  
    [category__and] => Array ( )  
    [post__in] => Array ( )  
    [post__not_in] => Array ( )  
    [tag__in] => Array ( )  
    [tag__not_in] => Array ( )  
    [tag__and] => Array ( )  
    [tag_slug__in] => Array ( )  
    [tag_slug__and] => Array ( )  
    [ignore_sticky_posts] =>  
    [suppress_filters] =>  
    [cache_results] => 1  
    [update_post_term_cache] => 1  
    [update_post_meta_cache] => 1  
    [post_type] =>  
    [nopaging] =>  
    [comments_per_page] => 50  
    [no_found_rows] => 
)

查询Wordpress表示执行以查找这些帖子($GLOBALS['wp_query']->request):

SELECT SQL_CALC_FOUND_ROWS wp_5_posts.ID 
FROM wp_5_posts 
WHERE 1=1 AND wp_5_posts.post_type = 'post' AND (wp_5_posts.post_status = 'publish') 
ORDER BY wp_5_posts.post_date desc LIMIT 0, 5

如果我在数据库上执行此查询,则生成的ID为:

12059
12046
12038
12030
12026

但是,如果我循环播放帖子:

foreach($posts as $p){
    echo($p->ID."<br>");
}

我得到以下ID:

11741
11721
11643
12059
12046
12038
12030
12026

有谁知道这是怎么回事?在调用query_posts之前,数组$ posts是空的,我不明白为什么这些帖子会在数组中出现。如果我在我的MySQL数据库中手动选择这些帖子,那么它们之间没有明显的区别,这会使前三个在某种程度上变得特别,而且这三个都比其他5个要求的要早。

提前致谢!

1 个答案:

答案 0 :(得分:0)

您是否尝试查看两种查询的搜索类型?我记得有一次我遇到这个问题,我使用wp_query和query_posts查询帖子,在一个例子中,我只获得了POST,而在其他情况下,我获得了所有页面/媒体附件和帖子