首页 文章

Wordpress - 使用自定义帖子类型管理员搜索

提问于
浏览
1

我已经在我的Wordpress中设置了一个新的帖子类型,除了一件事以外一切正常 .

在管理面板中,我有每种类型的帖子列表,但是当我进行搜索时(表格在右上角),它不关心帖子类型 . 当我在文章中研究时:我的结果中有文章和其他帖子类型 . 对于另一种类型也是如此 .

在我的URL中,我有post_type参数但它似乎不起作用 . 例子:http://mywebsite.fr/wp-admin/edit.php?s=contentofsearch&post_status=all&post_type=mytype&action=-1&m=0&seo_filter&paged=1&action2=-1

任何的想法 ?谢谢

1 回答

  • 2

    你可以使用add_action函数的下一个wordpress钩子:

    // search fix for ACF
    function extend_admin_search( $query ) {
    
        if ( $query->is_search ) {
    
            if ($query->query['post_type'] == 'contest') {
                $query->set( 'post_type',  'contest' );
            } else {
                $query->set( 'post_type', 'post' );
            }
        }
    
        return $query;
    
    }
    add_action( 'pre_get_posts', 'extend_admin_search' );
    

相关问题