wporg-developer
wporg-developer copied to clipboard
Search.php: Issues when clearing search in wp admin.
When you clear a search on a custom post type, you get an error in Wp-admin.
I think this issue has always existed in the local environment as git blame takes me back to the import commit.
GIF
Steps to reproduce
- Visit any of the custom post types locally
- Search for something
- Clear the input box and search ago.
- Notice you get the following error:
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /var/www/html/wp-content/themes/wporg-developer-2023/inc/search.php:237 Stack trace: #0 /var/www/html/wp-includes/class-wp-hook.php(324): DevHub_Search::redirect_empty_search(Array, Object(WP_Query)) #1 /var/www/html/wp-includes/plugin.php(256): WP_Hook->apply_filters(Array, Array) #2 /var/www/html/wp-includes/class-wp-query.php(3530): apply_filters_ref_array('the_posts', Array) #3 /var/www/html/wp-includes/class-wp-query.php(3824): WP_Query->get_posts() #4 /var/www/html/wp-includes/class-wp.php(696): WP_Query->query(Array) #5 /var/www/html/wp-includes/class-wp.php(816): WP->query_posts() #6 /var/www/html/wp-includes/functions.php(1336): WP->main(Array) #7 /var/www/html/wp-admin/includes/post.php(1304): wp(Array) #8 /var/www/html/wp-admin/includes/class-wp-posts-list-table.php(165): wp_edit_posts_query() #9 /var/www/html/wp-admin/edit.php(235): WP_Posts_List_Table->prepare_items() #10 {main} thrown in /var/www/html/wp-content/themes/wporg-developer-2023/inc/search.php on line 237
Also produces as warning on production. We just need to skip in admin context this code or change the context to be more specific as it's currently running on the_posts.