wporg-developer icon indicating copy to clipboard operation
wporg-developer copied to clipboard

Search.php: Issues when clearing search in wp admin.

Open StevenDufresne opened this issue 2 years ago • 1 comments

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

Screen Capture on 2023-11-13 at 15-08-23

Steps to reproduce

  1. Visit any of the custom post types locally
  2. Search for something
  3. Clear the input box and search ago.
  4. 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

StevenDufresne avatar Nov 13 '23 06:11 StevenDufresne

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.

pkevan avatar Feb 05 '24 16:02 pkevan