0

对于 Wordpress 模板,我在 functions.php 文件中创建了几个自定义帖子类型。目前,当我执行以下查询时,我的 MacBook 和 iPhone 上的帖子类型显示正确:

只有特定的“新闻”帖子类型:

$args = array( 'post_type' => 'news' ); query_posts($args);

多种自定义帖子类型:

$args = array( 'post_type' => array('sponsors','news','teams','businessclub','events') ); query_posts($args);

奇怪的是,在其他几个设备上,只有自定义帖子类型“新闻”没有显示,其他设备在查询中使用多种自定义帖子类型。

谁能帮我解决这个奇怪的事情?

4

2 回答 2

0

为什么不将第一个数组中的 post_type 粘贴$args到它自己的数组中呢?

$args = array( 'post_type' => array('news') ); 
query_posts($args);
于 2012-09-19T18:20:37.757 回答
0

将此添加到您的 function.php 文件中:

add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {

    if ( is_home() && $query->is_main_query() )
        $query->set( 'post_type', array( 'post', 'news' ) );

    return $query;
}

这应该使一切正常。在这里找到解决方案:http: //justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page

于 2015-10-07T11:02:00.193 回答