WordPress.org

Ready to get started?Download WordPress

Forums

Exclude an author (6 posts)

  1. seankelley
    Member
    Posted 6 years ago #

    I'm attempting to exclude an author from the loop using the following code, but have not had any success.

    <?php while (have_posts()) : the_post(); ?>
      <?php if (is_author('2')) continue; ?>

    Please advise - thanks in advance.

    _sean

  2. cryonics
    Member
    Posted 6 years ago #

    Try

    <?php while (have_posts() && (!is_author('2'))) : the_post(); ?>

    I have in my theme

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    in this case, could be better to do:

    <?php if (have_posts()&& (!is_author('2')) : while (have_posts()) : the_post(); ?>

  3. Kafkaesqui

    Posted 6 years ago #

    is_author() is intended to test for an author query. Not likely to work here.

    I think a better way to exclude an author from your posts loop is to just make sure they never make it to it. So initialize your loop with the following (that is, place this in your template before the loop begins):

    <?php query_posts($query_string . '&author=-2'); ?>

    Note the negative value on the author ID.

  4. seankelley
    Member
    Posted 6 years ago #

    Thanks to you both.. I'm using Kafkaesqui's snippet and it works perfectly.

    Kafkaesqui - is that handle a reference to the squid and the whale?

  5. Kafkaesqui

    Posted 6 years ago #

    A reference to The Squid and the Whale? Hehehe, heavens no.

    I can't make a claim for it being a reference to much of anything, but if it was it would probably be how life can take something strange, sidle up to you nice and friendly like, then hammer you upside the head with it.

  6. seankelley
    Member
    Posted 6 years ago #

    Speakin the truth!

    In any case, there's this funny scene in that movie where the kid calls a Kafka book "Kafka-esque"

    Thanks again for the help.

Topic Closed

This topic has been closed to new replies.

About this Topic