Site logo

Archived topic

Issues with Media Library due to GP

16 replies · Started by Margot on November 12, 2018

Viewing posts 1–15 of 17

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!

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

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?

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.

Can you show me a screenshot of the problem?

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

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

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.

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?

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 );
    }
}

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 );
    }
}

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

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 );
    }
}

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 );
    }
}
This archived topic is closed to new replies.