SHARE
TWEET

Custom Post Type Query - Wordpress 3.0

a guest Aug 11th, 2010 12,265 Never
  1. /**
  2.  * Do the work to pagination work on custom post types listing pages.
  3.  * OBS: Importante lembrar que a pagina de listagem não pode ter a mesma key do post_type
  4.  *
  5.  * @author @rafaelxy
  6.  * @param array $query args array, as it works on wordpress (dont use it as string)
  7.  * @return array set global $posts and return it as well
  8.  */
  9. define('PER_PAGE_DEFAULT', 10);
  10. function custom_query_posts(array $query = array())
  11. {
  12.         global $wp_query;
  13.         wp_reset_query();
  14.  
  15.         $paged = get_query_var('paged') ? get_query_var('paged') : 1;
  16.  
  17.         $defaults = array(
  18.                 'paged'                         => $paged,
  19.                 'posts_per_page'        => PER_PAGE_DEFAULT
  20.         );
  21.         $query += $defaults;
  22.  
  23.         $wp_query = new WP_Query($query);
  24. }
RAW Paste Data
Top