WordPress.org

Forums

wp_query (specific category & user) (4 posts)

  1. anthonyabraira
    Member
    Posted 2 years ago #

    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>
    
    <div class="grid_17 push_7">
    <?php
    $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(); ?>
  2. luckdragon
    Member
    Posted 2 years ago #

    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));
  3. anthonyabraira
    Member
    Posted 2 years ago #

    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 ...??

  4. luckdragon
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic