Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

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();
?>
share|improve this question
    
While your Question is beyond my scope, I thought I'd comment on the first line: $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;. You're unnecessarily running the function get_query_var twice. Better would be: $paged = get_query_var('paged'); if ( ! $paged ) $paged = 1;. –  akTed Jan 20 '13 at 3:12
add comment

1 Answer 1

There isn't a week query variable, but there is w: http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters

w (int) - Week of the year (from 0 to 53). Uses the MySQL WEEK command. The mode is dependent on the "start_of_week" option.

Your args should look like this:

$args = array('category_name' => 'whats-happening', 'year' => 2012, 'w' => 46 ,'paged' => $paged);
share|improve this answer
    
this does in fact work; however, my pagination fails to show up at the bottom of the page with this query. Any idea would this could be? –  Brian Jan 20 '13 at 15:55
    
You mean the numbered page links on the bottom of the page? –  Manny Fleurmond Jan 20 '13 at 21:29
    
The next_posts_link() and previous_posts_link() aren't showing. I'm guessing this is because I am only querying for a specific year and week value? I thought I would be able to to see an "Older" and "Newer" pagination link. –  Brian Jan 21 '13 at 2:31
    
Are there enough posts for those links to show up? –  Manny Fleurmond Jan 21 '13 at 2:50
    
yes, there are enough posts. –  Brian Jan 21 '13 at 3:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.