Searching multiple custom post types under one admin menu
-
Earlier you brilliantly helped me display multiple custom post types under 1 admin menu (https://ww.wp.xz.cn/support/topic/multiple-custom-post-types-under-one-admin-menu/, https://ww.wp.xz.cn/support/topic/list-all-posts-of-all-post-types-in-a-single-admin-interface/).
Which I implemented with this code in the functions.php file:
<?php function all_posts_from_post_types( $query ) { if ( ! is_admin() ) { return; } if ( ! $query->is_main_query() ) { return; } if ( isset( $_GET['post_type'] ) && 'show_all' === $_GET['post_type'] ) { $query->set( 'post_type', [ 'post_type_1' , 'post_type_2' , 'post_type_3' , 'post_type_4' ] ); } } add_action( 'pre_get_posts', 'all_posts_from_post_types' ); ?>When I try to search from this newly created admin page, I get a WordPress error
Invalid post type.
This is because the search button is redirecting to URL below (notepost_type=Array):
https://mysite.com/wp-admin/edit.php?s=Sample+Search+String&post_status=all&post_type=ArrayIf I manually change the URL to the below (note change of
post_type=show_all), I to get search results.
https://mysite.com/wp-admin/edit.php?s=Sample+Search+String&post_status=all&post_type=show_allDo you have any suggestions on how to make the ‘Search’ button work so users do not have to manually change the URL? How can I make the search button redirect to post_type=show_all instead of post_type=Array?
Thank you
The topic ‘Searching multiple custom post types under one admin menu’ is closed to new replies.