Want more features on Pastebin? Sign Up, it's FREE!
Guest

Custom Post Type Query - Wordpress 3.0

By: a guest on Aug 11th, 2010  |  syntax: PHP  |  size: 0.68 KB  |  views: 9,372  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data