首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress私人帖子不会显示给其他管理员

Wordpress私人帖子不会显示给其他管理员
EN

WordPress Development用户
提问于 2021-07-09 13:29:26
回答 1查看 54关注 0票数 0

默认情况下,Wordpress私有帖子对所有管理员都是可见的。但是由于某种原因,在这个构建上,私有帖子只会向创建它的管理员显示(在页面上)。我很困惑。我需要所有的管理员看到私人帖子显示。

这是一种使用自定义查询的自定义post类型,所以我可能在那里做了一些事情。

代码语言:javascript
复制
// query upcoming webinars - Sort by date from date Picker
    $args_upcoming = array(
      'cat' => $thiscat_id,
      'numberposts' => -1,
      'meta_key'=>'webinar_date',  
      'orderby' => 'meta_value', 
      'order' => 'ASC',
      'meta_query' => array(
          'key' => 'webinar_date',
          'value' => $query_date,
          'compare' => '>=',
          'type' => 'DATE'
        ),
$upcoming_query = new WP_Query( $args_upcoming );

自定义post类型设置:

代码语言:javascript
复制
** START--- Custom Post Type Webinars ---*/
function custom_post_type_webinars() {
// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'Webinars', 'Post Type General Name', 'twentytwenty' ),
        'singular_name'       => _x( 'Webinar', 'Post Type Singular Name', 'twentytwenty' ),
        'menu_name'           => __( 'Webinars', 'twentytwenty' ),
        'parent_item_colon'   => __( 'Parent Webinar', 'twentytwenty' ),
        'all_items'           => __( 'All Webinars', 'twentytwenty' ),
        'view_item'           => __( 'View Webinar', 'twentytwenty' ),
        'add_new_item'        => __( 'Add New Webinar', 'twentytwenty' ),
        'add_new'             => __( 'Add New', 'twentytwenty' ),
        'edit_item'           => __( 'Edit Webinar', 'twentytwenty' ),
        'update_item'         => __( 'Update Webinar', 'twentytwenty' ),
        'search_items'        => __( 'Search Webinar', 'twentytwenty' ),
        'not_found'           => __( 'Not Found', 'twentytwenty' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentytwenty' ),
    );     
// Set other options for Custom Post Type
    $args = array(
        'label'               => __( 'Webinars', 'twentytwenty' ),
        'description'         => __( 'Upcoming Webinars', 'twentytwenty' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'custom-fields', ),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'public'              => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
        'show_in_rest' => true,
 
    );  
    register_post_type( 'webinars', $args );
} 
add_action( 'init', 'custom_post_type_webinars', 0 );
/** END-- Custom Post Type Webinars --------------*/

网站是https://ibkrwebinars.com/category/webinars-upcoming/

再次:我创建的私人帖子显示给我。但对其他登录的管理员和签证管理员则不然。

EN

回答 1

WordPress Development用户

发布于 2021-07-15 14:00:26

我找到的解决方案是在pre_get_posts函数中找到的:我添加了:

代码语言:javascript
复制
if ( is_user_logged_in() ) {
        $query->set( 'post_status', array('private', 'publish'));
    } 

功能的完整代码:

代码语言:javascript
复制
/*------- START add webinars custom post type to the main query loop----------*/
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if( is_category() ) {
    $post_type = get_query_var('post_type');
    // show private posts to admins too.
    if ( is_user_logged_in() ) {
        $query->set( 'post_status', array('private', 'publish'));
    } 
    if($post_type)
        $post_type = $post_type;
    else
        $post_type = array('nav_menu_item', 'post', 'webinars'); // don't forget nav_menu_item to allow menus to work!
    $query->set('post_type',$post_type);
    return $query;
    }
}
/*------- END add webinars custom post type to the main query loop----------*/
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/391675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档