如果用户已登录,请创建一个小插件,将自定义帖子类型添加到默认循环中。
// add custom post type to wp loop
add_filter( \'pre_get_posts\', \'fb_add_to_query\' );
// ads to query
function fb_add_to_query( $query ) {
if ( ! is_user_logged_in() ) // if user not logged in, return
return $query;
if ( is_admin() || is_preview() ) // return, if in backend or preview
return $query;
if ( ! isset( $query -> query_vars[\'suppress_filters\'] ) )
$query -> query_vars[\'suppress_filters\'] = FALSE;
// conditional tags for restrictions
if ( is_home() || is_front_page() && ( FALSE == $query -> query_vars[\'suppress_filters\'] ) )
$query->set( \'post_type\', array( \'post\', \'my_post_type\' ) );
return $query;
}