I really, really don't get it.

On my archive.php and category.php it doesn't find any content. I know the correct templates are loaded, but WP_Query just don't find any content.

This is what i've got for archive.php:


        get_template_part('page', 'mobile');

    echo '<div class="blog-page">';
    <h1>Arkiv: <?php echo ucfirst(get_the_date('F Y')); ?></h1>
    $blog = new WP_Query(array(
        'post_type'     => 'post',
        'year'          => get_the_date('Y'),
        'monthnum'      => get_the_date('n')

    while($blog->have_posts()): $blog->the_post();

</div> <!-- blog page -->

get_the_date() does return the correct year and monthnum, so why don't i get any results?

Excerpt file, as requested:

    <?php if(!is_single(get_the_ID())) : ?>
    <article class="hentry excerpt clearfix" id="post-<?php the_ID(); ?>">
        <header class="left">
            <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <small class="entry-meta author">
                <?php $post_categories = wp_get_post_categories(get_the_ID()); ?>
                Skrivet av <?php the_author(); ?> den <?php the_time('j F Y'); ?>, 
                    $output = '';
                    foreach($post_categories as $c){
                        $cat = get_category($c);
                        $output .= '<a href="'.get_category_link($c).'">'.$cat->name.'</a>, ';
                    echo substr($output, 0, -2);
        <div class="entry-content left">
            <?php if(has_post_thumbnail()): ?>
                <a class="left" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                    <div class="img-wrapper">
                        <?php the_post_thumbnail('blog_thumb', 'thumbnail'); ?>
            <?php endif; ?>

            <?php the_excerpt();?>
            <a href="<?php the_permalink(); ?>">Läs mer</a>
<?php endif; ?>
  • get_the_date grabs that data from your main query (the $wp_query global) but you're looping through your secondary query in $blog. Try and print_r the $blog object and see if it contains any results. If it does, you should also post the content of your excerpt.php file.
    – kovshenin
    Oct 16, 2012 at 8:20
  • I did indeed get results! $blog['posts'] contains the results i want to display. See OP update for excerpt file.
    – qwerty
    Oct 16, 2012 at 8:33

1 Answer 1


The is_single function (used in your excerpt.php file) returns true only when the main query contains one single post. Since you're calling get_template_part from an archives page, your query contains more than one post, so is_single returns false and your excerpt.php file bails. Remove the check for is_single and you should be good to go.

More about is_single: http://codex.wordpress.org/Function_Reference/is_single

More about conditional tags: http://codex.wordpress.org/Conditional_Tags

Hope this helps.

  • Yes, that was indeed the issue. It sort of works, but not quite as i want. When i click a blog post i want to display all blog posts below the one that is shown, but i don't want the current one that is shown to show up below itself. Get it? That's why i added the if(is_single()) code. Is there any workaround to do what i want?
    – qwerty
    Oct 16, 2012 at 8:46
  • 2
    Maybe you want to add post__not_in parameter to the WP_Query. It excludes certain posts from the results. Oct 16, 2012 at 9:24
  • Yup, that did it!
    – qwerty
    Oct 16, 2012 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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