WordPress.org

Ready to get started?Download WordPress

Forums

Query Question. How to show posts from specific author (9 posts)

  1. lacohido
    Member
    Posted 6 years ago #

    Hello all-
    I'm trying to do a query where only the admins posts are shown.
    My ultimate goal is to have the admins post shown in its own loop and all other authors shown in another on the same page.
    But first things first. I can't get the query/loop to show just the admins posts.
    Here's what I have:

    <?php if (have_posts()) : ?>
    
    <?php query_posts('author=1&numberposts=4'); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2> <small>Viewed <?php the_view_count(); ?> Times</small>
    <span id="l_writtenby">by <span id="l_author"><?php the_author(); ?></span></span>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    
    <div class="entry">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    </div>
    
    <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
    </div>
    
    <?php endwhile; ?>
    
    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    </div>
    
    <?php else : ?>
    
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.
    
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
    
    <?php endif; ?>

    Any Suggestions are greatly appreciated
    Thanks
    -Landon

  2. Hella
    Member
    Posted 6 years ago #

    Did you try:

    <?php query_posts($query_string."&author=1"); ?>

  3. lacohido
    Member
    Posted 6 years ago #

    Hella-
    Still nothing... Is it where I'm putting the query?
    Thanks
    -Landon

  4. Hella
    Member
    Posted 6 years ago #

    Not sure, sorry. Definitely needs to be outside The Loop but you already have it there.

  5. goofydg1
    Member
    Posted 6 years ago #

    I'm not sure why you are trying to do this so this might work for you or not. I have a family site and wanted people to see a couple of the authors individually on the side so I used a simple text widget with index.php?author=1 (1 being the number of an author) to display the individual author. Very easy and separates an author out and I don't have to mess with the loop.

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Well, ideally, query_posts should be before the if (have_posts()) line, but I can't see that it would make any difference in such a case.

    Go look at the Users page, make sure that the admin is user number 1. Can't think of why he would not be, but hey, it's possible.

    Passing author=1 to query_posts should indeed work.

  7. lacohido
    Member
    Posted 6 years ago #

    Thanks Everyone-
    I'll mess with it some more and let you guys know my results

  8. lacohido
    Member
    Posted 6 years ago #

    Weird Thing-
    I tried the query Hella proposed on a different WordPress site I'm running and it worked fine (It displayed only the author that I specified). Very weird. they are both running 2.3.3
    Any Suggestions
    -Landon

  9. lacohido
    Member
    Posted 6 years ago #

    Could it Be???-
    I transferred the wordpress to another webhost and the "author" query worked like a charm. Could it be that MySql is set up different on the webbhosts? I transferred from Ixwebhosting to MediaTemple DV.
    Thanks
    -Landon

Topic Closed

This topic has been closed to new replies.

About this Topic