Support » Fixing WordPress » wp_query (specific category & user)

  • I am trying to create a simple author.php file that extracts things written by a specific author and from designated categories. I have read on get_posts and it seems that wp_query is what I need to get this effect. However, this code is not doing it for me. It still shows all the users, though it is able to isolate to the right category:

    <?php if (have_posts()) : ?>
    <?php // $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    <div class="grid_17 push_7">
    <?php /* If this is an author archive */ if (is_author()) { ?>
    <h2 class="pagetitle hide">Author Archive</h2>
    <?php } ?>
    <div class="grid_17 push_7">
    $author_id = get_the_author_meta( 'ID' ); //nab the current author id
    $author_spec = new WP_Query('cat=1', '&author=' .$author_id . '&paged='.$paged);
    while ($author_spec->have_posts()) : $author_spec->the_post(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • have you echoed $author_id to make sure that it’s returning the correct value?

    and shouldn’t it be more like:

    $author_spec = new WP_QUERY(array('cat' => 1, 'author' => $author_id, 'paged' => $paged));

    luckdragon / thanks for the prompt reply. I had done the check on the author earlier on but now when I try it (also using your array) it returns my user as 0 }} zero {{

    Is it because I am the administrator account for when I installed WP …??

    $getid = $posts[0]->post_author;
    $author_id = get_the_author_meta(‘ID’,$getid);

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_query (specific category & user)’ is closed to new replies.