【问题标题】:Wordpress taxonomies when listing custom post types列出自定义帖子类型时的 Wordpress 分类法
【发布时间】:2014-09-01 11:40:32
【问题描述】:

我正在注册一个自定义帖子类型“rv-events”,它具有分类“rv-categories”。在您通常会获得这些帖子的表格的管理页面上,您会获得一个表格,其中包含标题、类别分类法和按预期发布的日期。

这都是默认值和预期的,但是,现在我正在使用 add_filter('manage_edit-events_columns', 'change_column_titles') 更改表格的列标签。使用“change_column_titles”功能,我设法编辑列标题,但自定义分类列的数据丢失了。我只是得到一个 - 用于分类而不是像不更改列名时那样列出我的分类。

对于分类,我将 show_admin_column 设置为 true,所以这不是问题。其他人有任何想法吗?谢谢!

所以为了简短起见,问题是:当我更改其列标签时,我无法在自定义帖子类型的概览表中显示/列出分类。

注册帖子类型:

    $labels = array(
        ...
    );

    $args = array(
        'label' => 'Events',
        'labels' => $labels,
        'public'             => true,
        // 'publicly_queryable' => false,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'events' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'custom-fields', 'thumbnail')
    );

    register_post_type('rv-events', $args);

注册分类:

    $labels = array( 
        ...
    );

    $args = array( 
        'labels' => $labels,
        'public' => true,
        'show_in_nav_menus' => true,
        'show_ui' => true,
        'show_tagcloud' => true,
        'show_admin_column' => true,
        'hierarchical' => true,
        'rewrite' => true,
        'query_var' => true
    );

    register_taxonomy( 'rv_categories', array('rv-events'), $args );

添加自定义列

add_filter( 'manage_edit-rv-events_columns', 'column_titles') ;

function column_titles($columns) {
    return array(
        'cb' => '<input type="checkbox" />',
        'title' => 'Title',
        'start_date' => '<i class="fa fa-calendar-o"></i> Start Date',
        'end_date' => '<i class="fa fa-calendar-o"></i> End Date',
        'repeat' => '<i class="fa fa-repeat"></i> Repeat',
        'venue' => '<i class="fa fa-map-marker"></i> Venue',
        'categories' => 'Categories',
        'date' => '<i class="fa fa-calendar-o"></i> Date'
    );
}

【问题讨论】:

  • 您能否显示您用于注册自定义帖子类型/分类的代码以及添加自定义列的代码?
  • @ssergei 是的,请查看编辑
  • 所以为了简短起见,问题是:当我更改其列标签时,我无法在自定义帖子类型的概览表中显示/列出分类。

标签: wordpress custom-post-type taxonomy


【解决方案1】:

更改您的标题函数以使用您正在更改的列的实际名称:

function column_titles($columns) {
    return array(
        'cb' => '<input type="checkbox" />',
        'title' => 'Title',
        'start_date' => '<i class="fa fa-calendar-o"></i> Start Date',
        'end_date' => '<i class="fa fa-calendar-o"></i> End Date',
        'repeat' => '<i class="fa fa-repeat"></i> Repeat',
        'venue' => '<i class="fa fa-map-marker"></i> Venue',
        'taxonomy-rv_categories' => 'Categories',
        'date' => '<i class="fa fa-calendar-o"></i> Date'
    );
}

“类别”是为实际的 WordPress 帖子类别保留的。如果您创建的自定义分类不被视为“类别”。

【讨论】:

  • 谢谢,完成了! :)
猜你喜欢
  • 2015-03-15
  • 2013-06-22
  • 1970-01-01
  • 2013-07-14
  • 1970-01-01
  • 2013-08-03
  • 1970-01-01
  • 2014-05-15
  • 2011-03-20
相关资源
最近更新 更多