Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

Using this solution : Paginate result set from $wpdb->get_results()Paginate result set from $wpdb->get_results()

I did make my code for Authors list page template as follow:

<div>    
<table id="mytable"><tbody>

<?php
 // Get the authors from the database ordered by user's display name
 global $wpdb;
 $query = "SELECT ID, display_name from $wpdb->users ORDER BY display_name LIMIT 10";
 $author_ids = $wpdb->get_results($query);
$authcount = -1;

$total = $wpdb->get_var("
    SELECT COUNT(ID)
    FROM $wpdb->users
");
$authors_per_page = 10;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;

echo paginate_links( array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'prev_text' => __('&laquo;'),
    'next_text' => __('&raquo;'),
    'total' => ceil($total / $authors_per_page),
    'current' => $page
));
 
 // Loop through each author
 foreach($author_ids as $author) :
 // Get user data
 $curauth = get_userdata($author->ID);
 
 // If user_ID is 1 or 24, remove them from list
 if( ! in_array($curauth->ID, array(1, 24 )) ) :
 // Get link to author page
 $user_link = get_author_posts_url($curauth->ID);
    $post_count = get_usernumposts($curauth->ID);
 ?>
<tr<?php echo $authcount % 2 ? ' class="odd"' : ''; ?>>
<td>
<?php echo $authcount; ?>
</td><th scope="row">
<a href="<?php echo $user_link; ?>" title="<?php echo $curauth->display_name; ?>"><?php echo $curauth->display_name; ?></a>
</th><td>
( <?php echo $post_count; ?> )
</td></tr>

<?php endif; ?>
<?php $authcount = $authcount + 1; ?>
<?php endforeach; ?>

</tbody></table><br /></div>

But every page-number link display only the authors list from 1 to 10, whereas the database have a list of atleast 50-authors. Please help me to find out the error and its rectification. Thanks a lot.

Using this solution : Paginate result set from $wpdb->get_results()

I did make my code for Authors list page template as follow:

<div>    
<table id="mytable"><tbody>

<?php
 // Get the authors from the database ordered by user's display name
 global $wpdb;
 $query = "SELECT ID, display_name from $wpdb->users ORDER BY display_name LIMIT 10";
 $author_ids = $wpdb->get_results($query);
$authcount = -1;

$total = $wpdb->get_var("
    SELECT COUNT(ID)
    FROM $wpdb->users
");
$authors_per_page = 10;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;

echo paginate_links( array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'prev_text' => __('&laquo;'),
    'next_text' => __('&raquo;'),
    'total' => ceil($total / $authors_per_page),
    'current' => $page
));
 
 // Loop through each author
 foreach($author_ids as $author) :
 // Get user data
 $curauth = get_userdata($author->ID);
 
 // If user_ID is 1 or 24, remove them from list
 if( ! in_array($curauth->ID, array(1, 24 )) ) :
 // Get link to author page
 $user_link = get_author_posts_url($curauth->ID);
    $post_count = get_usernumposts($curauth->ID);
 ?>
<tr<?php echo $authcount % 2 ? ' class="odd"' : ''; ?>>
<td>
<?php echo $authcount; ?>
</td><th scope="row">
<a href="<?php echo $user_link; ?>" title="<?php echo $curauth->display_name; ?>"><?php echo $curauth->display_name; ?></a>
</th><td>
( <?php echo $post_count; ?> )
</td></tr>

<?php endif; ?>
<?php $authcount = $authcount + 1; ?>
<?php endforeach; ?>

</tbody></table><br /></div>

But every page-number link display only the authors list from 1 to 10, whereas the database have a list of atleast 50-authors. Please help me to find out the error and its rectification. Thanks a lot.

Using this solution : Paginate result set from $wpdb->get_results()

I did make my code for Authors list page template as follow:

<div>    
<table id="mytable"><tbody>

<?php
 // Get the authors from the database ordered by user's display name
 global $wpdb;
 $query = "SELECT ID, display_name from $wpdb->users ORDER BY display_name LIMIT 10";
 $author_ids = $wpdb->get_results($query);
$authcount = -1;

$total = $wpdb->get_var("
    SELECT COUNT(ID)
    FROM $wpdb->users
");
$authors_per_page = 10;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;

echo paginate_links( array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'prev_text' => __('&laquo;'),
    'next_text' => __('&raquo;'),
    'total' => ceil($total / $authors_per_page),
    'current' => $page
));
 
 // Loop through each author
 foreach($author_ids as $author) :
 // Get user data
 $curauth = get_userdata($author->ID);
 
 // If user_ID is 1 or 24, remove them from list
 if( ! in_array($curauth->ID, array(1, 24 )) ) :
 // Get link to author page
 $user_link = get_author_posts_url($curauth->ID);
    $post_count = get_usernumposts($curauth->ID);
 ?>
<tr<?php echo $authcount % 2 ? ' class="odd"' : ''; ?>>
<td>
<?php echo $authcount; ?>
</td><th scope="row">
<a href="<?php echo $user_link; ?>" title="<?php echo $curauth->display_name; ?>"><?php echo $curauth->display_name; ?></a>
</th><td>
( <?php echo $post_count; ?> )
</td></tr>

<?php endif; ?>
<?php $authcount = $authcount + 1; ?>
<?php endforeach; ?>

</tbody></table><br /></div>

But every page-number link display only the authors list from 1 to 10, whereas the database have a list of atleast 50-authors. Please help me to find out the error and its rectification. Thanks a lot.

edited tags
Link
hakre
  • 12.9k
  • 6
  • 49
  • 85
Source Link
syed
  • 59
  • 1
  • 5

Authors list Pagination : result set from $wpdb->get_results()

Using this solution : Paginate result set from $wpdb->get_results()

I did make my code for Authors list page template as follow:

<div>    
<table id="mytable"><tbody>

<?php
 // Get the authors from the database ordered by user's display name
 global $wpdb;
 $query = "SELECT ID, display_name from $wpdb->users ORDER BY display_name LIMIT 10";
 $author_ids = $wpdb->get_results($query);
$authcount = -1;

$total = $wpdb->get_var("
    SELECT COUNT(ID)
    FROM $wpdb->users
");
$authors_per_page = 10;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;

echo paginate_links( array(
    'base' => add_query_arg( 'cpage', '%#%' ),
    'format' => '',
    'prev_text' => __('&laquo;'),
    'next_text' => __('&raquo;'),
    'total' => ceil($total / $authors_per_page),
    'current' => $page
));
 
 // Loop through each author
 foreach($author_ids as $author) :
 // Get user data
 $curauth = get_userdata($author->ID);
 
 // If user_ID is 1 or 24, remove them from list
 if( ! in_array($curauth->ID, array(1, 24 )) ) :
 // Get link to author page
 $user_link = get_author_posts_url($curauth->ID);
    $post_count = get_usernumposts($curauth->ID);
 ?>
<tr<?php echo $authcount % 2 ? ' class="odd"' : ''; ?>>
<td>
<?php echo $authcount; ?>
</td><th scope="row">
<a href="<?php echo $user_link; ?>" title="<?php echo $curauth->display_name; ?>"><?php echo $curauth->display_name; ?></a>
</th><td>
( <?php echo $post_count; ?> )
</td></tr>

<?php endif; ?>
<?php $authcount = $authcount + 1; ?>
<?php endforeach; ?>

</tbody></table><br /></div>

But every page-number link display only the authors list from 1 to 10, whereas the database have a list of atleast 50-authors. Please help me to find out the error and its rectification. Thanks a lot.