WordPress.org

Support

Support » How-To and Troubleshooting » Exclude posts with certain post formats in query_posts

Exclude posts with certain post formats in query_posts

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters

    check out the last example in the taxonomy parameters section

    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?

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

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude posts with certain post formats in query_posts’ is closed to new replies.
Skip to toolbar