Display all posts of a post format.

I want to display all posts of a post format (let’s say: aside). In WordPress to display all posts of a certain category, just need to use this URL: mysite.com/category/mycategory. Is there a similar way to display all posts of a post format? Or any other way is also fine for me.

Related posts

Leave a Reply

4 comments

  1. You could use tax_query parameters to get the posts by post_format. For example:

    $args = array(
        'post_type'=> 'post',
        'post_status' => 'publish',
        'order' => 'DESC',
        'tax_query' => array(
            array(
                'taxonomy' => 'post_format',
                'field' => 'slug',
                'terms' => array( 'post-format-aside' )
            )
        )
    );
    

    Then you can iterate over the results with get_posts() (or use WP_Query() and a standard a Loop):

    $asides = get_posts( $args );
    if ( count($asides) ) {
        foreach ( $asides as $aside ) {
            // do something here...
        }
    }
    
  2. // this will get all 'quote' post format    
    $args = array(
        'tax_query' => array(
            array(
                'taxonomy' => 'post_format',
                'field' => 'slug',
                'terms' => array( 'post-format-quote' )
                )
            )
        );
    $query = new WP_query($args);
    while($query->have_posts()) : $query->the_post();
    // do whatever you want with it
    endwhile;
    
  3. See The Loop.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    That code above list all of the post on your wordpress site, so to show all post from a category you need the use the if ( in_category('CategoryNumberHere ') function to only fetch post from a category. You must also know the number of the category in your WordPress installation.

    Take a look at the linked page above, it has a full tutorial and layout of how to do such things. The code specific to categories is the second section down.