我正在使用代码段来包含来自自定义帖子类型的帖子"视频"在类别中导致WordPress。
代码是:
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','videos');
$query->set('post_type',$post_type);
return $query;
}
}
在返回正确结果方面,此代码确实有效。然而,它奇怪地使网站菜单不起作用。在调查中,我收到以下错误:
Notice: Undefined property: stdClass::$db_id in /homepages/16/d673645047/htdocs/SiteName/wp-includes/class-wp-walker.php on line 136
Notice: Undefined property: stdClass::$ID in /homepages/16/d673645047/htdocs/SiteName/wp-includes/class-walker-nav-menu.php on line 126
Notice: Undefined property: stdClass::$ID in /homepages/16/d673645047/htdocs/SiteName/wp-includes/class-walker-nav-menu.php on line 164
Notice: Undefined property: stdClass::$ID in /homepages/16/d673645047/htdocs/SiteName/wp-includes/nav-menu-template.php on line 547
Notice: Undefined property: stdClass::$ID in /homepages/16/d673645047/htdocs/SiteName/wp-includes/nav-menu-template.php on line 550
Notice: Undefined property: stdClass::$title in /homepages/16/d673645047/htdocs/SiteName/wp-includes/class-walker-nav-menu.php on line 204
Notice: Undefined property: stdClass::$ID in /homepages/16/d673645047/htdocs/SiteName/wp-includes/class-walker-nav-menu.php on line 204
有谁知道如何解决此问题?我已经测试过,上面的代码片段就是问题所在。我在网上看到这是一个已知问题,但一直无法找到解决方案。
答案 0 :(得分:1)
我不确定您的问题具体是什么,但我查询自定义帖子类型的方法略有不同。
<?php
$args = array( 'post_type' => 'testimonials_list', 'order' => 'ASC' );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?> //Do Something <?php endforeach;?>