BuddyDev

Search

[Resolved] Gallery Created But Not Showing Up

  • Participant
    Level: Initiated
    Posts: 16
    1002 on #9764

    Hello,
    I asked to the dev team of my theme and they said : “we don’t pre parse the loop on any of our themes.”

    I can see I’m not alone to have this issue but nobody have solution…

    I’m sure mediapress is a nice plugin but I can’t use it :/

  • Keymaster
    (BuddyDev Team)
    Posts: 22211
    Brajesh Singh on #9765

    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.

  • Participant
    Level: Initiated
    Posts: 16
    1002 on #9793

    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/

    • This reply was modified 5 years, 5 months ago by 1002.
    • This reply was modified 5 years, 5 months ago by 1002. Reason: Query Monitor is nice
  • Keymaster
    (BuddyDev Team)
    Posts: 22211
    Brajesh Singh on #9807

    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
    Brajesh

  • Participant
    Level: Initiated
    Posts: 16
    1002 on #9818

    \o\ \o/ /o/

    Perfect, everything works.

    THANK YOU VERY MUCH, I hope this topic can help other users.

    🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 22211
    Brajesh Singh on #9820

    Thank 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.

This topic is: resolved