[Resolved] Issues with Media Library due to GP

Home Forums Support [Resolved] Issues with Media Library due to GP

Home Forums Support Issues with Media Library due to GP

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #725674
    Margot

    Hi there,

    I’m having issues where my Media Library is only partially loading images that have been uploaded. Some images are present but others have disappeared. When I switch to a different theme the problem goes away. Please help. Thank you!

    #725746
    Leo
    Staff
    Customer Support

    Hi there,

    Can you try #1 here to eliminate any plugin conflicts first?
    https://docs.generatepress.com/article/debugging-tips/

    Let me know 🙂

    #725761
    Margot

    I tested for plugin conflicts and also reinstalled the WordPress core files. Still experiencing issues.

    #725771
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    The theme itself doesn’t have any control over the Media Library.

    Does it happen with GP Premium activated as well?

    Any visible errors? If not, any errors in your error_log file?

    #726023
    Margot

    It happens with GP Premium as well. I don’t see anything in the error_log.

    I thought it might be my child theme causing the problem so switched to use only the parent theme and it has the same problem. If I switch to a default WordPress theme (i.e. Twenty Seventeen), the images from the Media Library load without issues.

    #726319
    Tom
    Lead Developer
    Lead Developer

    Can you show me a screenshot of the problem?

    #726358
    Margot

    Here’s an example. Only 16 images show up in the media library and it doesn’t allow the library to show more than 16 images at a time, even when I’m using search function.

    https://prnt.sc/lhw6n9

    #726415
    Tom
    Lead Developer
    Lead Developer

    And there are more items than that? What if you click the list icon? (under the word “Media”)

    #726430
    Margot

    If I click on the list icon it shows the full list of images (2,396 items). But if I go back to clicking the grid icon it only shows the most recent 16 images.

    #726513
    Margot

    Hmm. One thing that’s standing out to me is that I have this snipped loaded in functions.php
    I got it via this link > https://generatepress.com/forums/topic/blog-add-on-different-number-of-post-in-first-page-of-blog/#post-372928 :

    add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
    function tu_change_posts_per_page( &$query ) {
        if ( ! is_main_query() ) {
            return;
        }
    
        if ( ! $query->is_paged ) {
            $query->set( 'posts_per_page', 16 );
        }
    }
    

    I added it so that the first page of the blog (as well as all first pages of blog archives like tag or blog category) only display 16 posts per page. But maybe it’s stopping other elements on the backend from loading. Could this be a cause in theory?

    #726692
    Tom
    Lead Developer
    Lead Developer

    Yep, that’ll do it.

    Try changing it to this:

    add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
    function tu_change_posts_per_page( &$query ) {
        if ( ! is_main_query() ) {
            return;
        }
    
        if ( is_admin() ) {
            return;
        }
    
        if ( ! $query->is_paged ) {
            $query->set( 'posts_per_page', 16 );
        }
    }
    #726730
    Margot

    That worked. However, I’m worried that there may be a situation down the line where something else involving posts might end up getting hidden from viewers… Could this work if I wanted it only ever to affect the blog and blog archives?

    add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
    function tu_change_posts_per_page( &$query ) {
        if ( ! is_main_query() ) {
            return;
        }
    
        if ( (! $query->is_paged ) && (class_exists('archive')) || (! $query->is_paged ) && (class_exists('category'))) {
            $query->set( 'posts_per_page', 16 );
        }
    }
    #726757
    Tom
    Lead Developer
    Lead Developer

    Instead of class_exists, do is_archive() and is_category().

    #727342
    Margot

    Would that be this?

    add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
    function tu_change_posts_per_page( &$query ) {
        if ( ! is_main_query() ) {
            return;
        }
    
        if ( (! $query->is_paged ) && (! $query->is_archive ) || (! $query->is_paged ) && (! $query->is_category )) {
            $query->set( 'posts_per_page', 16 );
        }
    }
    #727346
    Tom
    Lead Developer
    Lead Developer

    Try this:

    add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
    function tu_change_posts_per_page( &$query ) {
        if ( ! is_main_query() || is_admin() ) {
            return;
        }
    
        if ( ! $query->is_paged && ( $query->is_archive || $query->is_category ) ) {
            $query->set( 'posts_per_page', 16 );
        }
    }
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.