管理面板搜索不适用于特定的自定义帖子类型

时间:2017-09-18 作者:Mustafa Söylemez

你好,我有两种自定义的帖子类型,分别是“漫画”和“博伦”。我可以在“漫画”帖子类型上搜索帖子,但当我尝试在“bolum”帖子类型上搜索时,我会从“漫画”中得到结果,如果我尝试第二次搜索,则会显示一个错误页面,如“无效帖子类型”。

这是我在函数中自定义的帖子类型代码。php

    function register_bolumpost() {
    $labels = array(
        \'name\' => _x( \'Bölümler\', \'my_custom_post\',\'custom\' ),
        \'singular_name\' => _x( \'Bölüm\', \'my_custom_post\', \'custom\' ),
        \'all_items\'=> _x( \'Tüm Bölümler\', \'my_custom_post\', \'custom\' ),
        \'add_new\' => _x( \'Yeni Ekle\', \'my_custom_post\', \'custom\' ),
        \'add_new_item\' => _x( \'Yeni Bölüm Ekle\', \'my_custom_post\', \'custom\' ),
        \'edit_item\' => _x( \'Bölümü Düzenle\', \'my_custom_post\', \'custom\' ),
        \'new_item\' => _x( \'Yeni Bölüm\', \'my_custom_post\', \'custom\' ),
        \'view_item\' => _x( \'Bölümü Görüntüle\', \'my_custom_post\', \'custom\' ),
        \'search_items\' => _x( \'Bölüm Ara\', \'my_custom_post\', \'custom\' ),
        \'not_found\' => _x( \'Bölüm Bulunamadı\', \'my_custom_post\', \'custom\' ),
        \'not_found_in_trash\' => _x( \'Çöp Kutusunda Bölüm Bulunamadı\', \'my_custom_post\', \'custom\' ),
        \'parent_item_colon\' => _x( \'Bölüm\', \'my_custom_post\', \'custom\' ),
        \'menu_name\' => _x( \'Bölümler\', \'my_custom_post\', \'custom\' ),
    );

    $args = array(
        \'labels\' => $labels,
        \'hierarchical\' => false,
        \'description\' => \'Bölüm Postu\',
        \'supports\' => array( \'title\', \'editor\', \'comments\'),
        \'taxonomies\' => array(\'mangalar_cat\'),
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 7,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'query_var\' => true,
        \'can_export\' => true,
        \'public\' => true,
        \'has_archive\' => true,
        \'capability_type\' => \'post\'
    );  
    register_post_type( \'bolum\', $args );
} 

add_action( \'init\', \'register_bolumpost\'); 
add_post_type_support( \'bolum\', \'post-formats\' );

function register_mangapost() {

    $labels2 = array(
        \'name\' => _x( \'Mangalar\', \'my_custom_post2\',\'custom2\' ),
        \'singular_name\' => _x( \'Manga\', \'my_custom_post2\', \'custom2\' ),
        \'all_items\'=> _x( \'Tüm Mangalar\', \'my_custom_post2\', \'custom2\' ),
        \'add_new\' => _x( \'Yeni Ekle\', \'my_custom_post2\', \'custom2\' ),
        \'add_new_item\' => _x( \'Yeni Manga Ekle\', \'my_custom_post2\', \'custom2\' ),
        \'edit_item\' => _x( \'Mangayı Düzenle\', \'my_custom_post2\', \'custom2\' ),
        \'new_item\' => _x( \'Yeni Manga\', \'my_custom_post2\', \'custom2\' ),
        \'view_item\' => _x( \'Mangayı Görüntüle\', \'my_custom_post2\', \'custom2\' ),
        \'search_items\' => _x( \'Manga Ara\', \'my_custom_post2\', \'custom2\' ),
        \'not_found\' => _x( \'Manga Bulunamadı\', \'my_custom_post2\', \'custom2\' ),
        \'not_found_in_trash\' => _x( \'Çöp Kutusunda Manga Bulunamadı\', \'my_custom_post2\', \'custom2\' ),
        \'parent_item_colon\' => _x( \'Manga\', \'my_custom_post2\', \'custom2\' ),
        \'menu_name\' => _x( \'Mangalar\', \'my_custom_post2\', \'custom2\' ),
    );

    $args2 = array(
        \'labels\' => $labels2,
        \'hierarchical\' => false,
        \'description\' => \'Manga Postu\',
        \'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'comments\' ),
        \'taxonomies\' => array( \'durum_cat\', \'turler_cat\', \'mangalar_cat\'),
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'menu_position\' => 4,
        \'show_in_nav_menus\' => true,
        \'publicly_queryable\' => true,
        \'exclude_from_search\' => false,
        \'query_var\' => true,
        \'can_export\' => true,
        \'public\' => true,
        \'has_archive\' => true,
        \'capability_type\' => \'post\' 
    );

    register_post_type( \'manga\', $args2 );

}

add_action(\'init\', \'register_mangapost\');
add_post_type_support( \'manga\', \'post-formats\' );
这是我的全部功能。php,如果需要的话。https://paste.ee/p/wtdsz

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

当我在上注册多个自定义帖子类型时init 胡克,我不使用多重add_action 功能。考虑一下这一点:

function m_register_custom_posts() {
 register_bolumpost();
 register_mangapost();
}
add_action(\'init\',\'m_register_custom_posts\');
我还想将所有自定义分类法函数调用添加到此函数中,因为它们在同一个init 钩在init 钩子,并且您没有指定激发它们的优先级。这可能会导致问题。通过在init 钩住单个函数,您可以控制自定义函数的触发顺序。

第91行似乎有一个限制查询的过滤器集。

add_filter( \'pre_get_posts\', \'tgm_io_cpt_search\' );
function tgm_io_cpt_search( $query ) {

if ( $query->is_search ) {
$query->set( \'post_type\', array( \'manga\') );
}

return $query;

}
尝试移除该过滤器,看看会发生什么。

结束

相关推荐