2
votes

I have set up a new post type in my Wordpress and all work fine except one thing.

In the administration panel I have the list of post for each type but when I make a search (with the form on top right corner) it doesn't care about the post type. When I research in article : I have article and other post type in my results. Same thing for the other type.

In my URL I have the post_type parameter but it doesn't seem to work. Exemple : 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

Any idea ? Thanks

1

1 Answers

2
votes

You may use next wordpress hook with add_action function:

// 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' );