0

I feel like I've been banging my head against the keyboard for a week with this problem. I'm trying to change my current query on my home page to show only posts that are set as standard posts using the new post format.

I've looked everywhere for answers (including here and here) and tried everything I've found, but I can't get it to work within the framework of my current query.

My query is provided below. Any help is greatly appreciated.

<?php     
query_posts( array( 'post__not_in' => $ids, 'showposts' => 10, 'cat' => '-4' ) ); ?>
<?php while (have_posts()) : the_post(); ?>
-LOOP STUFF-
  <?php the_excerpt(); ?><BR>
<?php endwhile; ?>

UPDATE - March 30: Since I posted this I found out how to properly query for, we'll say, image posts using this code:

    <?php 
$args = array(
  'post__not_in' => $ids, 
  'showposts' => 10, 
  'cat' => '-4,-1866,-27',
  'tax_query' => array(
    array(
      'taxonomy' => 'post_format',
      'field' => 'slug',
      'terms' => 'post-format-image'
    )
  )
);        
    query_posts( $args ); ?>
<!-- Look Stuff -->
    <?php endwhile; ?>

But I still need to figure out how to do the opposite and only pull standard posts.

Second Update - March 30: I found the answer after some more hunting. Apparently the only way to pull the standard posts is to add:

'operator' => 'NOT IN',

So it looks for posts that aren't in the image post format. Or I have to add an array of terms to the terms line so it won't return any of those formats. Odd, but it works.

5
  • As a minor addendum, perhaps the site needs a tag for post format now?
    – Andrew
    Commented Mar 22, 2011 at 16:53
  • 2
    you dont need to exlclude all other posts formats just use 'tax_query' => array( array( 'taxonomy' => 'post-format', 'field' => 'slug', 'terms' => array( 'post-format-quote' ) ) ) to get only your wanted post type
    – Bainternet
    Commented Mar 22, 2011 at 17:14
  • Where's the post format specific code in your query then? +1 Bainternet..
    – t31os
    Commented Mar 22, 2011 at 17:14
  • @Bainternet I haven't been able to get the tax_query to work for me with the query I use above. If you can be specific it would be helpful.
    – Andrew
    Commented Mar 23, 2011 at 18:43
  • Just a heads up the codex was wrong the other day, I think it is now changed, it is 'taxonomy' => 'post_format' . Underscore not hyphen. This is for Bainternet's comment , it looks right in your code.
    – Wyck
    Commented Mar 30, 2011 at 16:54

1 Answer 1

0

Okay, I found the answer after some more hunting. Apparently the only way to pull the standard posts is to add:

'operator' => 'NOT IN',

So it looks for posts that aren't in the image post format. Or I have to add an array of terms to the terms line so it won't return any of those formats. Odd, but it works.

<?php 
$args = array(
  'post__not_in' => $ids, 
  'showposts' => 10, 
  'cat' => '-4,-1866,-27',
  'tax_query' => array(
    array(
      'taxonomy' => 'post_format',
      'field' => 'slug',
      'terms' => 'post-format-image',
      'operator' => 'NOT IN'
    )
  )
);  
    query_posts( $args ); ?>
<!-- The Loop -->
    <?php endwhile; ?>
1
  • Unfortunately, as I understand tax_query, doing a NOT IN query to exclude all formats except for the standard one would be an extremely slow performance-wise. Commented Sep 20, 2012 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.