自定义帖子类型显示和工作,但空白快速编辑

时间:2019-11-24 作者:Debbie Kurth

我有个神秘的问题。我已经成功创建了一个自定义的帖子类型,以及相关的类别。但是,当我列出帖子时,“快速编辑”部分不会显示标题、日期或任何信息。它是空白的,我不知道为什么。有人能看到问题吗?

//////////////////////// setup admin pages
add_action( \'init\', \'mmd_client_tracking_form\', 0 );                            // Add the menu
function mmd_client_tracking_form()
{
  $labels = array(
    \'name\'               => _x( \'Review Client Workouts\', \'mmd_client_list\' ),
    \'singular_name\'      => _x( \'Manage Clients\', \'mmd_client_list\' ),
    \'add_new\'            => _x( \'New Client\', \'mmd_client_list\' ),
    \'add_new_item\'       => __( \'Add New Client\' ),
    \'edit_item\'          => __( \'Edit Client\' ),
    \'new_item\'           => __( \'New Client\' ),
    \'all_items\'          => __( \'Workout Clients\' ),
    \'view_item\'          => __( \'View Client\' ),
    \'search_items\'       => __( \'Search Clients\' ),
    \'not_found\'          => __( \'No Clients found\' ),
    \'not_found_in_trash\' => __( \'No Clients found in the Trash\' ), 
    \'parent_item_colon\'  => \'\',
    \'menu_name\'          => \'Biorider Tracking\'
  );


  $args = array(
    \'register_meta_box_cb\' => \'mmdtrack_meta_box\', // Register a meta box
    \'labels\'               => $labels,
    \'description\'          => \'This post type holds all posts for your directory items.\',
    \'public\'               => true,
    \'menu_position\'        => 10,
    \'show_ui\'              => true,
    \'supports\'             => array( \'title\' ),
    \'has_archive\'          => true,
    \'menu_icon\'            => \'dashicons-media-spreadsheet\',
  );
  register_post_type( \'mmdtrack\', $args );  

}


//-----------------------------------------------------------------
// CUSTOM CATAGORY
//-----------------------------------------------------------------
add_action( \'init\', \'mmd_track_taxonomies\', 0 );                                  // Add the standard submenu
function mmd_track_taxonomies() {

  $labels = array(
        \'name\'              => _x( \'Biorider Categories\', \'Biorider Categories\' ),
        \'singular_name\'     => _x( \'Category\', \'taxonomy singular name\' ),
        \'search_items\'      => __( \'Search Clients Categories\' ),
        \'all_items\'         => __( \'All Clients Categories\' ),
        \'parent_item\'       => __( \'Parent Clients Categories\' ),
        \'parent_item_colon\' => __( \'Parent Clients Category:\' ),
        \'edit_item\'         => __( \'Edit Clients Category\' ),
        \'update_item\'       => __( \'Update Clients Category\' ),
        \'add_new_item\'      => __( \'Add New Clients Category\' ),
        \'new_item_name\'     => __( \'New Clients Category Name\' ),
        \'menu_name\'         => __( \'Clients Categories\')
  );
  $args = array(
        \'hierarchical\'      => true,
        \'labels\'            => $labels,
        \'show_ui\'           => true,
        \'show_admin_column\' => true,
        \'query_var\'         => true,
        \'rewrite\'           => array( \'slug\' => \'mmdtrack_cat\' )
  );

  register_taxonomy( \'mmdtrack_cat\', \'mmdtrack\', $args );
}

add_action( \'init\', \'mmd_tracking_menu\', 0 );                                          // Add the standard submenu
function mmd_tracking_menu()
{

add_submenu_page(\'edit.php?post_type=mmdtrack\',   // Parent Slug from add_menu_page 
                 \'Biorider Settings\',             // Title of page
                 \'Settings\',                      // Menu title
                 \'manage_options\',                // Minimum capability to view the menu.
                 \'mmd_Tracking_Settings_slug\',    // Unqiue Slug Name
                 \'mmd_trackingAdminPage\' );    // A callback function used to display page content. 

}





//-----------------------------------------------------------------
// ENTRIES OF MEMBER LISTINGS - MANUAL
//-----------------------------------------------------------------
function mmdtrack_meta_box(WP_Post $post)
 { 
 $prefix = \'mmdtrack\';                               // Custom Post Name    
 add_meta_box($prefix, \'Set Tracking\', mmdtrack_client_tracking_form);  
 }

function  mmdtrack_client_tracking_form($PostId)
{
... displaying code for metabox
}



////////////////////////////////////////////////////////////////////////
//  THIS HOOKS IN TO WORDPRESS CUSTOM POST AND CHANGES THE 
//  MANAGE LIST FORM
//////////////////////////////////////////////////////////////////////
add_filter(\'manage_mmdtrack_posts_columns\', \'mmd_member_track_columns_head\');
function mmd_member_track_columns_head($defaults) {

    $new_columns[\'cb\'] = \'<input type="checkbox" />\';
    $new_columns[\'mmd_member_name\']                    = \'Name\';
    $new_columns[\'mmd_member_tracking_workout_count\']  = \'Number of Workouts\';
    $new_columns[\'mmd_member_memberships\']             = \'Active Membershps\';
    $new_columns[\'mmd_member_category\']                = \'Categories\';

    return $new_columns;
}



add_action(\'manage_mmdtrack_posts_custom_column\', \'mmd_track_columns_content\', 10, 2);
function mmd_track_columns_content($column_name, $post_ID)
{

switch($column_name)
 {  
  case \'mmd_member_name\': 
      $Name  = get_the_title( $post_ID );
      echo $Name;
  break;

  case \'mmd_member_tracking_workout_count\':
     $user_ID = mmd_track_FindUser($post_ID);
     echo mmd_track_GetWorkoutCnt($user_ID);
  break;

   case \'mmd_member_memberships\':
     $user_ID = mmd_track_FindUser($post_ID);
     if($user_ID==0)
       echo "None";
  break;

  case \'mmd_member_category\':
    $terms = get_the_terms( $post_ID, \'mmdtrack_cat\' );

    /* If terms were found. */
    if ( !empty( $terms ) ) 
        {
        $out = array();

        /* Loop through each term, linking to the \'edit posts\' page for the specific term. */
        foreach ( $terms as $term ) 
           {
           $out[] = sprintf( \'<a href="%s">%s</a>\',
                    esc_url( add_query_arg( array( \'post_type\' => \'mmdtrack\', \'mmdtrack_cat\' => $term->slug ), \'edit.php\' ) ),
                    esc_html( sanitize_term_field( \'name\', $term->name, $term->term_id, \'mmdtrack_cat\', \'display\' ) )
                           );
           }

         /* Join the terms, separating them with a comma. */
         echo join( \', \', $out );
        }

  break;        

 }
}






function mmd_track_emptytrash($post_ID)
{
if(get_post_status( $post_id ) === \'trash\') 
  ClearMemberWorkouts($post_ID);

return 0;       
}
add_action( \'before_delete_post\', \'mmd_track_emptytrash\');

////////////////////////////////////////////////////////////
//  If a list is trashed, make sure all the list records are
//  removed from the table.
////////////////////////////////////////////////////////////
function mmd_track_place_in_trash($post_ID)
{
}
add_action(\'wp_trash_post\', \'mmd_track_place_in_trash\');



2 个回复
最合适的回答,由SO网友:jg314 整理而成

该问题似乎与您的mmd_member_track_columns_head() 作用不是修改默认列,而是将其完全覆盖,导致快速编辑功能停止工作。特别是title 键必须是数组的一部分才能工作。尝试以下操作:

add_filter(\'manage_mmdtrack_posts_columns\', \'mmd_member_track_columns_head\');
function mmd_member_track_columns_head( $defaults ) {

    // Modify the existing columns, instead of overwriting them.
    $defaults[\'title\']                             = \'Name\';
    $defaults[\'mmd_member_tracking_workout_count\'] = \'Number of Workouts\';
    $defaults[\'mmd_member_memberships\']            = \'Active Membershps\';

    // Remove the "Date" column if you don\'t want it.
    unset( $defaults[\'date\'] );

    return $defaults;
}
此代码执行以下操作:

它保留“标题”列以允许快速编辑功能工作,但将其重命名为“名称”。这还应该允许您删除用于从中输出标题的代码mmd_track_columns_content() 因为WordPress会自动执行此操作mmd_member_category 列,因为WordPress会自动输出关联的分类术语。这还应该允许您从中删除代码mmd_track_columns_content().

我希望这是有益的。如果你有任何问题,请告诉我。

SO网友:Debbie Kurth

多亏了Jg314,答案很简单。我拿走了默认标题,一旦恢复,一切都恢复了。

错误的方式。删除此$new_columns[\'mmd_member_name\'] 如下所示

function mmd_member_track_columns_head($defaults) {

    $new_columns[\'cb\'] = \'<input type="checkbox" />\';
    $new_columns[\'mmd_member_name\']                    = \'Name\';
    $new_columns[\'mmd_member_tracking_workout_count\']  = \'Number of Workouts\';
    $new_columns[\'mmd_member_memberships\']             = \'Active Membershps\';
    $new_columns[\'mmd_member_category\']                = \'Categories\';

    return $new_columns;
}

add_action(\'manage_mmdtrack_posts_custom_column\', \'mmd_track_columns_content\', 10, 2);
function mmd_track_columns_content($column_name, $post_ID)
{
然后删除关联的密钥case \'mmd_member_name\':

switch($column_name)
 {  
  case \'mmd_member_name\': 
      $Name  = get_the_title( $post_ID );
      echo $Name;
  break;

  case \'mmd_member_tracking_workout_count\':
     $user_ID = mmd_track_FindUser($post_ID);
     echo mmd_track_GetWorkoutCnt($user_ID);
  break;

   case \'mmd_member_memberships\':
     $user_ID = mmd_track_FindUser($post_ID);
     if($user_ID==0)
       echo "None";
  break;

  case \'mmd_member_category\':
    $terms = get_the_terms( $post_ID, \'mmdtrack_cat\' );

    /* If terms were found. */
    if ( !empty( $terms ) ) 
        {
        $out = array();

        /* Loop through each term, linking to the \'edit posts\' page for the specific term. */
        foreach ( $terms as $term ) 
           {
           $out[] = sprintf( \'<a href="%s">%s</a>\',
                    esc_url( add_query_arg( array( \'post_type\' => \'mmdtrack\', \'mmdtrack_cat\' => $term->slug ), \'edit.php\' ) ),
                    esc_html( sanitize_term_field( \'name\', $term->name, $term->term_id, \'mmdtrack_cat\', \'display\' ) )
                           );
           }

         /* Join the terms, separating them with a comma. */
         echo join( \', \', $out );
        }

  break;        

 }
}



是什么修复了它。添加回$new_columns[\'title\'] = __(\'Title\');

add_filter(\'manage_mmdclienttrack_posts_columns\', \'mmd_member_track_columns_head\');
function mmd_member_track_columns_head($defaults) {

    $new_columns[\'cb\'] = \'<input type="checkbox" />\';
    $new_columns[\'title\']                             = __(\'Title\');
    $new_columns[\'mmd_member_tracking_workout_count\']  = \'Number of Workouts\';
    $new_columns[\'mmd_member_memberships\']             = \'Active Membershps\';
    $new_columns[\'mmd_member_category\']                = \'Categories\';

    return $new_columns;
}
```


相关推荐