Tagged: galleries, galleries not showing up
Sorry about that. Since we are using WP_Query for listing the media/galleries, It gets affected by the code modifying the args in correctly.
I have seen it for so many themes/plugins using the filter incorrectly that I am looking at a way to totally bypass the pre_get_posts filter in future.
oh, I found the issue!
In my functions.php, I used a function (maybe a bit old) to remove the woocommerce products of the research of the website (post and page).
[code]
function SearchFilter($query) {
if ( $query->is_search && !is_woocommerce() && !is_admin()) {
$query->set( ‘post_type’, ‘post,page’ );
}
if ( function_exists( ‘is_woocommerce’ ) ) :
if ( $query->is_search && is_woocommerce() && !is_admin()) {
$query->set( ‘post_type’, ‘product’ );
}
endif;
return $query;
}
add_filter(‘pre_get_posts’,’SearchFilter’);
[/code]When I remove this function, I can see the gallery.
Unfortunately, I need this function, if you have idea to modify the function, I will be very happy 😉
Thank you for your help.
Best Regards
PS: Thank you to the plugin Query Monitor who help me to found the issue.
https://wordpress.org/plugins/query-monitor/Hi Mary,
Thank you.I have simplified your function
function SearchFilter($query) { // if not main query, don't cause any issue. if ( ! $query->is_main_query() || is_admin() ) { return ; } if ( $query->is_search && function_exists( 'is_woocommerce' ) && is_woocommerce() ) { $query->set( 'post_type', 'product' ); } elseif( $query->is_search ) { $query->set( 'post_type', 'post,page' ); } } add_action( 'pre_get_posts','SearchFilter' );
It checks and modifies only the main query. It will still break the search pages for other plugins but should work for all other things.
Please try it and let me know if it works or not?
PS: I too like Query Monitor. It’s a great tool 🙂
Thank you
BrajeshThank you Mary.
I am glad it worked. Have a great time building your site 🙂
Marking it as resolved now.Regards
Brajesh
The topic ‘ [Resolved] Gallery Created But Not Showing Up’ is closed to new replies.