How to query for a week using key => value WP_Query argument notation?

I would like to be able to query for a specific year and week using WP_Query argument notation. I am using this notation as I would like the page to paginate.

What’s the correct “year” and “week” key value notation for performing the query in this manner?

Read More

I know I could do something like this, but I would like the page to paginate.

Here’s the bit of code I’m using for the key-value wp_query notation:

<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('category_name' => 'whats-happening', 'year' => 2012, 'week' => 46 ,'paged' => $paged);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);
if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>

HTML post structure to loop through....

<?php if ($wp_query->max_num_pages > 1) : ?>
    <?php next_posts_link( __('<span class="older">&larr; Older</span>') ); ?>
    <?php previous_posts_link( __('<span class="newer">Newer &rarr;</span>') ); ?>
<?php endif; ?>

<?php
    if (function_exists('wp_pagenavi')){ wp_pagenavi(); }
    $wp_query = null;
    $wp_query = $temp;
    wp_reset_query();
?>

Related posts

Leave a Reply

1 comment