Archived topic
Media Search Not Working After GP Theme Update
3 replies · Started by Randal on May 7, 2022
I updated to GP Version: 3.1.3 a few weeks ago.
When I go to the Media Library and search for an image, I get no results.
If I switch to any other theme and then do the search again, I get the expected results.
I went through the process of disabling plugins, etc., and it's the theme that is causing the issue.
Hi there,
are you using a child theme, or are there any custom functions or are you using any GP Element Hooks on the site ?
Yes, I am using a child theme.
In that theme, I have this function:
add_filter( 'pre_get_posts', 'custom_post_type_search' );
function custom_post_type_search( $query ) {
if ($query->is_search) {
$query->set('post_type', array( 'post', 'entry', 'document', 'image', 'video'));
}
return $query;
}
When I remove it, the Media Library search works, but the front-end search does not include all the Custom Post Types.
I modified the function:
add_filter( 'pre_get_posts', 'custom_post_type_search' );
function custom_post_type_search( $query ) {
if ($query->is_search && !is_admin()) {
$query->set('post_type', array( 'post', 'entry', 'document', 'image', 'video'));
}
return $query;
}
It appears to be working as expected. However, I'm very curious, and concerned, about this. Do you have any idea why this would happen only on the admin side and only for the Media Library?
Hi Randa,
I think it's related to how WP writes the media search function.