WordPress.org

Ready to get started?Download WordPress

Forums

Exclude posts with certain post formats in query_posts (5 posts)

  1. GATEKeeper
    Member
    Posted 3 years ago #

    I've been banging my head against the keyboard trying to figure this out. Does anyone know how to exclude a given post format in query_posts?

    For example, I don't want asides to appear on the front page.

    Up until now I've used this query to pull posts:

    <?php
    // this is where the Features module begins
    	query_posts( array( 'post__not_in' => $ids, 'showposts' => 10 ) ); ?>
        <?php while (have_posts()) : the_post(); ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img src="http://www.thegate.ca/wp-content/themes/mimbo2.2/timthumb.php?src=<?php getImage('1'); ?>&w=75&h=75&zc=1&q=100" class="alignleft" alt="<?php the_title(); ?>"></a><a href="<?php the_permalink() ?>" rel="bookmark" class="title">
          <?php the_title(); ?> &raquo;</a>
    	  <?php the_excerpt(); ?><BR>
        <?php endwhile; ?>

    In the line "query_posts( array( 'post__not_in' => $ids, 'showposts' => 10 ) )" I have tried using 'has_post_format' => 'standard', format, $format, and a bunch of other things, but nothing seems to work.

    Can anyone help me with this?

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters

    check out the last example in the taxonomy parameters section

  3. GATEKeeper
    Member
    Posted 3 years ago #

    Thanks. That does explain this a lot more, but I still can't get it to work (I'm only somewhat literate in coding).

    Perhaps it's worth noting that my index page starts with the query:

    <?php query_posts('showposts=1&meta_key=featured&meta_value=1');
       $ids = array();
       while (have_posts()) : the_post();
       $ids[] = get_the_ID(); ?>

    Then my second area on that page queries with:

    <?php query_posts( array( 'post__not_in' => $ids, 'showposts' => 4, 'cat' => 4 ) ); ?>'
    THE LOOP

    Followed by the last section:

    <?php query_posts( array( 'post__not_in' => $ids, 'showposts' => 10, 'cat' => '-4,-1866,-27' ) ); ?>
    THE LOOP

    Does that change anything?

  4. GATEKeeper
    Member
    Posted 3 years ago #

    Anyone have any ideas? This can't be that difficult, is it?

  5. lalaalaaa
    Member
    Posted 3 years ago #

    It's not that difficult, you just have to read carefully, since there are no examples! :) Rev. Voodoo's link had the answer in the operator parameter.

    Try:

    <?php
    $args = array(
      'tax_query' => array(
        array(
          'taxonomy' => 'post_format',
          'field' => 'slug',
          'terms' => 'post-format-XYZ',
          'operator' => 'NOT IN'
        )
      )
    );
    query_posts( $args );
    ?>

    Replace "XYZ" with the post format you want to exclude.

Topic Closed

This topic has been closed to new replies.

About this Topic