在管理区域按自定义分类对帖子进行排序

时间:2014-04-04 作者:Osu

EDIT

@kaiser-这个问题与您发布的答案略有不同,我说的是通过单击列标题进行排序,而不是添加下拉列表以按分类术语进行筛选(您将看到我已经在屏幕截图中这样做了)。

正如奥托在回答米洛的问题时所说:“不可能按分类法排序,因为从某种角度来看,这实际上没有多大意义。。。在帖子上使用分类法的目的实际上是在该分类法中包含在帖子之间共享的术语”。

我明白他的意思,因为一篇文章可以附加多个术语,按它们排序是没有意义的。我决定放弃这个想法,如果没有用的话,请随意删除这个帖子。谢谢

ENDEDIT

一直在网上搜寻解决方案,但没有找到我的问题的具体答案。我已经注册了一个自定义帖子类型和两个自定义分类法,但我试图允许管理员按照分类法对帖子进行排序,就像您可以使用日期列一样-请参见此处的屏幕截图:

enter image description here

有人知道怎么做吗?以下是我如何注册自定义帖子类型(如果有任何用处):

Class OSUFestivals
    {
        public static function init()
        {
            add_action( "init", array( __CLASS__, "register_directory_cpt" ) );
            add_action( "init", array( __CLASS__, "register_workshop_type_taxonomy" ) );
            add_action( "init", array( __CLASS__, "register_day_taxonomy" ) );
        }

        public static function register_directory_cpt()
        {
            $labels = array(
                \'name\'               => \'Festival Items\',
                \'singular_name\'      => \'Festival Item\',
                \'menu_name\'          => \'Festival\',
                \'name_admin_bar\'     => \'Festival Item\',
                \'add_new\'            => \'Add New Item\',
                \'add_new_item\'       => \'Add New Item\',
                \'new_item\'           => \'New Item\',
                \'edit_item\'          => \'Edit Item\',
                \'view_item\'          => \'View Item\',
                \'all_items\'          => \'All Items\',
                \'search_items\'       => \'Search Items\',
                \'parent_item_colon\'  => \'Parent Items:\',
                \'not_found\'          => \'No Items found.\',
                \'not_found_in_trash\' => \'No Items found in Trash.\',
            );
            $args = array(
                \'labels\'        => $labels,
                \'public\'        => true,
                \'hierarchical\'  => false,
                \'has_archive\'   => true,
                \'show_in_admin_bar\' => true,
                \'menu_position\' => 5,
                \'supports\'      => array( \'title\', \'editor\', \'thumbnail\', \'author\', \'excerpt\', \'revisions\', \'page-attributes\' ),
                \'rewrite\'       => array(
                    \'with_front\'    => false,
                    \'slug\'          => \'festival-Items\'
                )
            );

            register_post_type( \'lkfestival\', $args );
        }

        public static function register_workshop_type_taxonomy()
        {
            $labels = array(
                \'name\'                      => \'Workshop types\',
                \'singular_name\'             => \'Workshop type\',
                \'search_items\'              => \'Search workshop types\',
                \'all_items\'                 => \'All workshop types\',
                \'parent_item\'               => \'Parent workshop type\',
                \'edit_item\'                 => \'Edit workshop type\',
                \'update_item\'               => \'Update workshop type\',
                \'add_new_item\'              => \'Add new workshop type\',
                \'new_item_name\'             => \'New workshop type\',
                \'choose_from_most_used\'     => \'Choose from most used workshop types\'
            );

            $args = array(
                \'hierarchical\'      => true,
                \'labels\'            => $labels,
                \'show_admin_column\' => true,
                \'rewrite\'           => array( \'slug\' => \'event-type\' ),
                \'capabilities\'      => array (
                    /* Only let Andrea assign workshop types */
                    \'manage_terms\'  => \'manage_options\', // by default only admin
                    \'edit_terms\'    => \'manage_options\',
                    \'delete_terms\'  => \'manage_options\',
                    \'assign_terms\'  => \'edit_posts\'  // means administrator\', \'editor\', \'author\', \'contributor\'
                )
            );

            register_taxonomy( \'lktypes\', \'lkfestival\', $args );
        }

        public static function register_day_taxonomy()
        {
            $labels = array(
                \'name\'                      => \'Festival days\',
                \'singular_name\'             => \'Festival day\',
                \'search_items\'              => \'Search festival days\',
                \'all_items\'                 => \'All festival days\',
                \'parent_item\'               => \'Parent festival day\',
                \'edit_item\'                 => \'Edit festival day\',
                \'update_item\'               => \'Update festival day\',
                \'add_new_item\'              => \'Add new festival day\',
                \'new_item_name\'             => \'New festival day\',
                \'choose_from_most_used\'     => \'Choose from most used festival days\'
            );

            $args = array(
                \'hierarchical\'      => true,
                \'labels\'            => $labels,
                \'show_admin_column\' => true,
                \'rewrite\'           => array( \'slug\' => \'day\' ),
                \'capabilities\'      => array (
                    /* Only let Andrea assign festival days */
                    \'manage_terms\'  => \'manage_options\', // by default only admin
                    \'edit_terms\'    => \'manage_options\',
                    \'delete_terms\'  => \'manage_options\',
                    \'assign_terms\'  => \'edit_posts\'  // means administrator\', \'editor\', \'author\', \'contributor\'
                )
            );

            register_taxonomy( \'lkdays\', \'lkfestival\', $args );
        }

    }

    // Load Class
    OSUFestivals::init();
我认为“sort”参数register_taxonomy() 将允许排序,但这似乎与术语添加到对象的顺序有关。

1 个回复
SO网友:Jeff Sterup

下面是我在管理中按照自定义分类法对自定义帖子类型进行排序的步骤。我有一个名为plugin\\u filter的自定义帖子类型和一个名为filter\\u group的自定义分类法。我将以下过滤器添加到插件中,以使字段可排序。

add_filter("manage_edit-plugin_filter_sortable_columns", \'plugin_filter_sort\');
function plugin_filter_sort($columns) {
   $custom = array(
       \'taxonomy-filter_group\' => \'taxonomy-filter_group\'
   );
   return wp_parse_args($custom, $columns);
}

结束

相关推荐

Wp-admin上的自定义查询变量和解析请求

我读过这篇文章http://wordpress.org/support/topic/query-vars-in-admin虽然这是一个很老的问题,但它非常适合我。我正在努力完成我在这里发布的内容:Rewrite rule for admin-ajax.php但在下面的代码中,在wp admin中只调用第一个过滤器:add_action(\'init\', array(\'MYCLASS\', \'add_custom_rewrite_rules\'), 10, 1); add_action(\'q