Gallery pagination issue
-
Hey,
I found a problem with gallery pagination, which is working like this:
$pages = intval( $count_all_albums / $per_page ); if ( $count_all_albums % $per_page > 0 ) $pages += 1; $range = 100; if ( ! $pages ) { $pages = 1; } if ( 1 != $pages ) {
So if there is less galleries than it is allowed to display on one page – there is no need for pagination, fair enough. But the issue in my case was that variable $count_all_albums was always 0, so the pagination didn’t appear even when it should.
I found why, in file:
template/gallery-template.php
On line 31, I found:
$count_all_albums = $wpdb->get_var( "SELECT COUNT(*) FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'gallery' AND (wp_posts.post_status = 'publish')" );
I was quite surprised when I found this out 🙂 You’re using $wpdb, but even so, in query you put hardcoded table names. You know that a loooot of websites do not use wp_ prefix anymore? 🙂
I even have a fix for you:
$count_all_albums = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE 1=1 AND $wpdb->posts.post_type = 'gallery' AND ($wpdb->posts.post_status = 'publish')" );
Cheers.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Gallery pagination issue’ is closed to new replies.