Skip to main content
5 of 8
Rollback to Revision 3
PNMG
  • 1.4k
  • 1
  • 16
  • 19

How do I query by post format in WordPress 3.1

I am trying to query for all posts with a post format of 'quote.' I have added the post formats to my functions.php with

add_theme_support( 'post-formats', array( 'image', 'video', 'gallery', 'quote' ) );

I have selected 'quote' as the format for the post in the admin. The last example under Taxonomy_Parameters shows how to display posts that have the 'quote' format but when I run it in my theme no posts are returned. Here is the code:

$args = array(
  'tax_query' => array(
    array(
      'taxonomy' => 'post-format',
      'field' => 'slug',
      'terms' => 'post-format-quote'
    )
  )
);
query_posts( $args );

When I just query all posts and place

echo get_post_format();

in the loop it returns the word 'quote' on the front-end. Also, when I var_dump() the query I do not see anything in the array about post format.

Does anyone know if it is possible to query by post format? If so how?

EDIT - See 5 comment under Bainternet's answer: This is the code found on index.php of the twentyten theme of a fresh install trying to return format type quotes. I return 'no' instead of 'quote'. Can you see anything that I should change.

get_header(); ?>
        <div id="container">
            <div id="content" role="main">
        <?php $args = array(
                'tax_query' => array(
                    array(
                    'taxonomy' => 'post-format',
                        'field' => 'slug',
                        'terms' => array('quote')
                    )
                )
            );
      query_posts( $args );
      if ( have_posts() ) : while ( have_posts() ) : the_post();
      echo get_post_format();
      endwhile; else:
      echo 'no';
      endif;
      wp_reset_query();      
      ?>
            </div><!-- #content -->
        </div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

EDIT 2 - It appears that the WordPress Codex has now changed and the portion on Taxonomy Parameters is only found in Google cache. This problem remains unsolved and unfortunately it is not a simple syntax issue like many want to believe.

PNMG
  • 1.4k
  • 1
  • 16
  • 19