Advertisement
Guest User

Untitled

a guest
Sep 24th, 2014
667
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.60 KB | None | 0 0
  1. <?php
  2.     /**
  3.      * The WordPress Query class.
  4.      * @link http://codex.wordpress.org/Function_Reference/WP_Query
  5.      *
  6.      */
  7.     $args = array(
  8.        
  9.         //Post & Page Parameters
  10.         'p'             => 1,
  11.         'name'          => 'hello-world',
  12.         'page_id'       => 1,
  13.         'pagename'     => 'sample-page',
  14.         'post_parent'  => 1,
  15.         'post__in'     => array(1,2,3),
  16.         'post__not_in' => array(1,2,3),
  17.        
  18.         //Author Parameters
  19.         'author'      => '1,2,3,',
  20.         'author_name' => 'admin',
  21.        
  22.         //Category Parameters
  23.         'cat'              => 1,
  24.         'category_name'    => 'blog',
  25.         'category__and'    => array( 1, 2),
  26.         'category__in'     => array(1, 2),
  27.         'category__not_in' => array( 1, 2 ),
  28.        
  29.         //Type & Status Parameters
  30.         'post_type'   => 'any',
  31.         'post_status' => 'any',
  32.        
  33.         //Choose ^ 'any' or from below, since 'any' cannot be in an array
  34.         'post_type' => array(
  35.             'post',
  36.             'page',
  37.             'revision',
  38.             'attachment',
  39.             'my-post-type',
  40.             ),
  41.        
  42.         'post_status' => array(
  43.             'publish',
  44.             'pending',
  45.             'draft',
  46.             'auto-draft',
  47.             'future',
  48.             'private',
  49.             'inherit',
  50.             'trash'
  51.             ),
  52.        
  53.         //Order & Orderby Parameters
  54.         'order'               => 'DESC',
  55.         'orderby'             => 'date',
  56.         'ignore_sticky_posts' => false,
  57.         'year'                => 2012,
  58.         'monthnum'            => 1,
  59.         'w'                   => 1,
  60.         'day'                 => 1,
  61.         'hour'                => 12,
  62.         'minute'              => 5,
  63.         'second'              => 30,
  64.        
  65.         //Tag Parameters
  66.         'tag'           => 'cooking',
  67.         'tag_id'        => 5,
  68.         'tag__and'      => array( 1, 2),
  69.         'tag__in'       => array( 1, 2),
  70.         'tag__not_in'   => array( 1, 2),
  71.         'tag_slug__and' => array( 'red', 'blue'),
  72.         'tag_slug__in'  => array( 'red', 'blue'),
  73.        
  74.         //Pagination Parameters
  75.         'posts_per_page'         => 10,
  76.         'posts_per_archive_page' => 10,
  77.         'nopaging'               => false,
  78.         'paged'                  => get_query_var('paged'),
  79.         'offset'                 => 3,
  80.        
  81.         //Custom Field Parameters
  82.         'meta_key'       => 'key',
  83.         'meta_value'     => 'value',
  84.         'meta_value_num' => 10,
  85.         'meta_compare'   => '=',
  86.         'meta_query'     => array(
  87.             array(
  88.                 'key' => 'color',
  89.                 'value' => 'blue',
  90.                 'type' => 'CHAR',
  91.                 'compare' => '='
  92.             ),
  93.             array(
  94.                 'key' => 'price',
  95.                 'value' => array( 1,200 ),
  96.                 'compare' => 'NOT LIKE'
  97.             ),
  98.        
  99.         //Taxonomy Parameters
  100.         'tax_query' => array(
  101.         'relation'  => 'AND',
  102.             array(
  103.                 'taxonomy'         => 'color',
  104.                 'field'            => 'slug',
  105.                 'terms'            => array( 'red', 'blue' ),
  106.                 'include_children' => true,
  107.                 'operator'         => 'IN'
  108.             ),
  109.             array(
  110.                 'taxonomy'         => 'actor',
  111.                 'field'            => 'id',
  112.                 'terms'            => array( 1, 2, 3 ),
  113.                 'include_children' => false,
  114.                 'operator'         => 'NOT IN'
  115.             )
  116.         ),
  117.        
  118.         //Permission Parameters -
  119.         'perm' => 'readable',
  120.        
  121.         //Parameters relating to caching
  122.         'no_found_rows'          => false,
  123.         'cache_results'          => true,
  124.         'update_post_term_cache' => true,
  125.         'update_post_meta_cache' => true,
  126.        
  127.     );
  128.  
  129. $the_query = new WP_Query( $args );
  130.  
  131.  ?>
  132.  
  133.  
  134. <?php
  135. // the query to actually display the posts
  136. $the_query = new WP_Query( $args ); ?>
  137.  
  138. <?php if ( $the_query->have_posts() ) : ?>
  139.  
  140.     <!-- pagination here -->
  141.  
  142.     <!-- the loop -->
  143.     <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
  144.         <h2><?php the_title(); ?></h2>
  145.     <?php endwhile; ?>
  146.     <!-- end of the loop -->
  147.  
  148.     <!-- pagination here -->
  149.  
  150.     <?php wp_reset_postdata(); ?>
  151.  
  152. <?php else : ?>
  153.     <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
  154. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement