GregL71

rewrite wpdb help

Feb 20th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. global $wpdb, $_current_member;
  2.  
  3.     $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
  4.     $post_per_page = 2;
  5.     $offset = ($paged - 1)*$post_per_page;
  6.  
  7.     $activityTable = $wpdb->prefix . 'ams_activity';
  8.     $activityMetaTable = $wpdb->prefix . 'ams_activity_meta';
  9.  
  10. $activity_calls =
  11.     $wpdb->get_results(
  12.         $wpdb->prepare("
  13.            SELECT SQL_CALC_FOUND_ROWS
  14.                a.*, m.*                
  15.            FROM
  16.                $activityTable a
  17.            LEFT OUTER JOIN
  18.                (SELECT activity_id, meta_key, meta_value FROM $activityMetaTable)
  19.            AS
  20.                m
  21.            ON
  22.                a.id = m.activity_id
  23.            WHERE
  24.                a.user_id = %d
  25.            AND
  26.                a.type = %s
  27.            OR
  28.                a.type = %s
  29.            OR
  30.                a.type = %s
  31.            ORDER BY
  32.                time DESC
  33.            LIMIT
  34.                %d, %d"
  35.             , $_current_member->ID
  36.             , 'status_update'
  37.             , 'motivation_update'
  38.             , 'measurement_update'
  39.             , $offset
  40.             , $post_per_page
  41.             ), OBJECT);
  42.  
  43.  
  44.     $sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" );
  45.     $max_num_pages = ceil($sql_posts_total / $post_per_page);
  46.  
  47.  
  48.             foreach ($activity_calls as $row) {
  49.     //removed irrelevant loop stuff
  50.  
  51.             }
  52.  
  53. // this code adapted from ( http://wp.smashingmagazine.com/2013/09/26/powerful-wordpress-tips-and-tricks/ )
  54. $pagination = array(
  55.     'base'       => str_replace( 99999, '%#%', get_pagenum_link( 99999 ) ),
  56.     'format'     => '?paged=%#%',
  57.     'current'    => max( 1, get_query_var( 'paged' ) ),
  58.     'total'      => $max_num_pages,
  59.     'next_text'  => 'next',
  60.     'prev_text'  => 'previous'
  61. );
  62. echo '<div class="pagination primary-links">' . paginate_links( $pagination ) . '</div>';
Advertisement
Add Comment
Please, Sign In to add comment