Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.35 KB | None | 0 0
  1. $defaults = array(
  2.                 'numberposts' => 5, 'offset' => 0,
  3.                 'category' => 0, 'orderby' => 'post_date',
  4.                 'order' => 'DESC', 'include' => array(),
  5.                 'exclude' => array(), 'meta_key' => '',
  6.                 'meta_value' =>'', 'post_type' => 'post',
  7.                 'suppress_filters' => true
  8.         );
  9.     $r = wp_parse_args( $args, $defaults );
  10.     if ( empty( $r['post_status'] ) )
  11.                 $r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish';
  12.         if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) )
  13.                 $r['posts_per_page'] = $r['numberposts'];
  14.         if ( ! empty($r['category']) )
  15.                 $r['cat'] = $r['category'];
  16.         if ( ! empty($r['include']) ) {
  17.                 $incposts = wp_parse_id_list( $r['include'] );
  18.                 $r['posts_per_page'] = count($incposts);  // only the number of posts included
  19.                 $r['post__in'] = $incposts;
  20.         } elseif ( ! empty($r['exclude']) )
  21.                 $r['post__not_in'] = wp_parse_id_list( $r['exclude'] );
  22.  
  23.         $r['ignore_sticky_posts'] = true;
  24.         $r['no_found_rows'] = true;
  25.  
  26.     global $wpdb;
  27.     $querystr = "
  28.     SELECT wposts.ID AS post_id, wposts.post_author, wposts.post_date, wposts.post_date_gmt, wposts.post_content, wposts.post_title, wposts.post_excerpt,       wposts.post_status, wposts.comment_status, wposts.ping_status, wposts.pinged, wposts.post_modified, wposts.post_modified_gmt, wposts.post_parent,       wposts.guid, wposts.post_type, wposts.post_mime_type, wposts.comment_count, wpauthor.ID AS user_id, wpauthor.user_login, wpauthor.user_nicename,        wpauthor.user_status, wptax.*, wpterms.*, wptermsrel.*
  29.     FROM $wpdb->posts wposts
  30.     INNER JOIN  $wpdb->users wpauthor
  31.         ON wposts.post_author = wpauthor.ID    
  32.     INNER JOIN  $wpdb->term_relationships wptermsrel
  33.         ON wposts.ID = wptermsrel.object_id  
  34.     INNER JOIN  $wpdb->term_taxonomy wptax
  35.         ON wptermsrel.term_taxonomy_id = wptax.term_taxonomy_id  
  36.     INNER JOIN  $wpdb->terms wpterms
  37.         ON wptax.term_id = wpterms.term_id  
  38.     WHERE wposts.post_status = $r['post_status']
  39.     AND wposts.post_type = $r['post_type']
  40.     AND wposts.post_date < NOW()
  41.     GROUP BY wposts.ID
  42.     ORDER BY wposts.$r['orderby'] $r['order']
  43.     LIMIT $r['posts_per_page'], $r['offset']
  44.     ";
  45. $posts = $wpdb->get_results($querystr, OBJECT);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement