【问题标题】:One specific Wordpress custom post type not showing一种特定的 Wordpress 自定义帖子类型未显示
【发布时间】:2012-09-19 09:46:17
【问题描述】:

对于一个 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);

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

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

【问题讨论】:

    标签: wordpress custom-post-type


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回复。问题不在于 Wordpress 本身,但 Role Scoper 插件阻止了帖子类型的显示。我没有在其他设备上看到帖子的事实与我没有登录这些设备有关。愚蠢的我。
    【解决方案2】:

    将此添加到您的 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多