Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * The WordPress Query class.
- * @link http://codex.wordpress.org/Function_Reference/WP_Query
- *
- */
- $args = array(
- //Post & Page Parameters
- 'p' => 1,
- 'name' => 'hello-world',
- 'page_id' => 1,
- 'pagename' => 'sample-page',
- 'post_parent' => 1,
- 'post__in' => array(1,2,3),
- 'post__not_in' => array(1,2,3),
- //Author Parameters
- 'author' => '1,2,3,',
- 'author_name' => 'admin',
- //Category Parameters
- 'cat' => 1,
- 'category_name' => 'blog',
- 'category__and' => array( 1, 2),
- 'category__in' => array(1, 2),
- 'category__not_in' => array( 1, 2 ),
- //Type & Status Parameters
- 'post_type' => 'any',
- 'post_status' => 'any',
- //Choose ^ 'any' or from below, since 'any' cannot be in an array
- 'post_type' => array(
- 'post',
- 'page',
- 'revision',
- 'attachment',
- 'my-post-type',
- ),
- 'post_status' => array(
- 'publish',
- 'pending',
- 'draft',
- 'auto-draft',
- 'future',
- 'private',
- 'inherit',
- 'trash'
- ),
- //Order & Orderby Parameters
- 'order' => 'DESC',
- 'orderby' => 'date',
- 'ignore_sticky_posts' => false,
- 'year' => 2012,
- 'monthnum' => 1,
- 'w' => 1,
- 'day' => 1,
- 'hour' => 12,
- 'minute' => 5,
- 'second' => 30,
- //Tag Parameters
- 'tag' => 'cooking',
- 'tag_id' => 5,
- 'tag__and' => array( 1, 2),
- 'tag__in' => array( 1, 2),
- 'tag__not_in' => array( 1, 2),
- 'tag_slug__and' => array( 'red', 'blue'),
- 'tag_slug__in' => array( 'red', 'blue'),
- //Pagination Parameters
- 'posts_per_page' => 10,
- 'posts_per_archive_page' => 10,
- 'nopaging' => false,
- 'paged' => get_query_var('paged'),
- 'offset' => 3,
- //Custom Field Parameters
- 'meta_key' => 'key',
- 'meta_value' => 'value',
- 'meta_value_num' => 10,
- 'meta_compare' => '=',
- 'meta_query' => array(
- array(
- 'key' => 'color',
- 'value' => 'blue',
- 'type' => 'CHAR',
- 'compare' => '='
- ),
- array(
- 'key' => 'price',
- 'value' => array( 1,200 ),
- 'compare' => 'NOT LIKE'
- ),
- //Taxonomy Parameters
- 'tax_query' => array(
- 'relation' => 'AND',
- array(
- 'taxonomy' => 'color',
- 'field' => 'slug',
- 'terms' => array( 'red', 'blue' ),
- 'include_children' => true,
- 'operator' => 'IN'
- ),
- array(
- 'taxonomy' => 'actor',
- 'field' => 'id',
- 'terms' => array( 1, 2, 3 ),
- 'include_children' => false,
- 'operator' => 'NOT IN'
- )
- ),
- //Permission Parameters -
- 'perm' => 'readable',
- //Parameters relating to caching
- 'no_found_rows' => false,
- 'cache_results' => true,
- 'update_post_term_cache' => true,
- 'update_post_meta_cache' => true,
- );
- $the_query = new WP_Query( $args );
- ?>
- <?php
- // the query to actually display the posts
- $the_query = new WP_Query( $args ); ?>
- <?php if ( $the_query->have_posts() ) : ?>
- <!-- pagination here -->
- <!-- the loop -->
- <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
- <h2><?php the_title(); ?></h2>
- <?php endwhile; ?>
- <!-- end of the loop -->
- <!-- pagination here -->
- <?php wp_reset_postdata(); ?>
- <?php else : ?>
- <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement