WordPress.org

Support

Support » How-To and Troubleshooting » Exclude an author

Exclude an author

  • seankelley
    Member

    @seankelley

    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

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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(); ?>

    Kafkaesqui
    Member

    @kafkaesqui

    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.

    seankelley
    Member

    @seankelley

    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?

    Kafkaesqui
    Member

    @kafkaesqui

    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.

    seankelley
    Member

    @seankelley

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exclude an author’ is closed to new replies.