Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global $wpdb, $_current_member;
- $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
- $post_per_page = 2;
- $offset = ($paged - 1)*$post_per_page;
- $activityTable = $wpdb->prefix . 'ams_activity';
- $activityMetaTable = $wpdb->prefix . 'ams_activity_meta';
- $activity_calls =
- $wpdb->get_results(
- $wpdb->prepare("
- SELECT SQL_CALC_FOUND_ROWS
- a.*, m.*
- FROM
- $activityTable a
- LEFT OUTER JOIN
- (SELECT activity_id, meta_key, meta_value FROM $activityMetaTable)
- AS
- m
- ON
- a.id = m.activity_id
- WHERE
- a.user_id = %d
- AND
- a.type = %s
- OR
- a.type = %s
- OR
- a.type = %s
- ORDER BY
- time DESC
- LIMIT
- %d, %d"
- , $_current_member->ID
- , 'status_update'
- , 'motivation_update'
- , 'measurement_update'
- , $offset
- , $post_per_page
- ), OBJECT);
- $sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" );
- $max_num_pages = ceil($sql_posts_total / $post_per_page);
- foreach ($activity_calls as $row) {
- //removed irrelevant loop stuff
- }
- // this code adapted from ( http://wp.smashingmagazine.com/2013/09/26/powerful-wordpress-tips-and-tricks/ )
- $pagination = array(
- 'base' => str_replace( 99999, '%#%', get_pagenum_link( 99999 ) ),
- 'format' => '?paged=%#%',
- 'current' => max( 1, get_query_var( 'paged' ) ),
- 'total' => $max_num_pages,
- 'next_text' => 'next',
- 'prev_text' => 'previous'
- );
- echo '<div class="pagination primary-links">' . paginate_links( $pagination ) . '</div>';
Advertisement
Add Comment
Please, Sign In to add comment