BuddyDev

Search

[Resolved] Mediapress new optin request – Hide Empty Galleries

  • Participant
    Level: Master
    Posts: 413
    Venutius on #13016

    Hi Brajesh,

    I’ve got a new option request, I’d like to hide empty galleries from the edit.php gallery browser. Would that be possible. You see on my site I’ll be creating galleries in anticipation of future content, there’s no need for the users to see empty galleries as that will be uploading from the from end, so these are just dead-end click zones.

  • Participant
    Level: Master
    Posts: 413
    Venutius on #13017

    Oops sorry, I meant to say they would be uploading from the front-end.

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #13029

    Hi George,
    We can do it by using pre_get_posts filter in the admin and looking for _mpp_media_count meta on the galleries.

    I will post this code later today with the other thread(I am sorry I missed to post a solution there).

    Thank you
    Brajesh

  • Participant
    Level: Master
    Posts: 413
    Venutius on #13042

    Thanks Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #13153

    Hi George,
    Please use the following code

    
    
    /**
     * Hide empty MediaPress Gallery from admin galleries list.
     *
     * @param WP_Query $query query object.
     */
    function mpp_admin_hide_empty_galleries_from_galleries_page( $query ) {
    
    	if ( ! is_admin() || defined( 'DOING_AJAX' ) || ! $query->is_main_query() ) {
    		return;
    	}
    
    	if ( $query->get( 'post_type' ) != mpp_get_gallery_post_type() ) {
    		return;
    	}
    
    	$meta_query = array(
    		array(
    			'key'     => '_mpp_media_count',
    			'value'   => 1,
    			'compare' => '>=',
    		),
    	);
    
    	// side effect: it will override any other meta query for the galleries list.
    	$query->set( 'meta_query', $meta_query );
    }
    
    add_action( 'pre_get_posts', 'mpp_admin_hide_empty_galleries_from_galleries_page' );
    
    

    Hope this helps.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 413
    Venutius on #13159

    Thanks Brajesh that works great! I added a check to exclude the site admin and all is working exactly how I want it.

  • Keymaster
    (BuddyDev Team)
    Posts: 24501
    Brajesh Singh on #13165

    Thank you George.
    Good to know that 🙂

    Best Regards
    Brajesh

The topic ‘ [Resolved] Mediapress new optin request – Hide Empty Galleries’ is closed to new replies.

This topic is: resolved