0

I'm trying to exclude all post formats but standard from a page template loop that displays 4 latest posts. For some reason I can't get the query to work.

This is my page template

global $paged, $wp_query, $wp;
$args = wp_parse_args($wp->matched_query);
if ( !empty ( $args['paged'] ) ) {
$wp_query->set('paged', $args['paged']);
$paged = $args['paged'];
}

 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 query_posts('cat=0&posts_per_page=4&paged='.$paged); //set your own query here
 get_template_part( 'loop', 'portfolio' );

 wp_reset_query();

This is the loop

<?php $num_cols = 4; // set the number of columns here

for ( $i=1 ; $i <= $num_cols; $i++ ) :
    echo '<div class="column col-' . $i . '" >';
    $counter = $num_cols + 1 - $i; ?>

<?php while (have_posts()) : the_post();
    if( $counter%$num_cols == 0 ) :

// begin of core posts output ?>

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <header class="entry-header">
    POST STUFF
    <?php //end of posts output

    endif; $counter++;
        endwhile;
            rewind_posts();
        echo '</div>'; //closes the column div
    endfor; ?>
        <?php if (  $wp_query->max_num_pages > 1 || get_query_var('page')) : ?>
            <?php twentytwelve_content_nav( 'nav-below' ); ?>           
        <?php endif;
        wp_reset_query(); ?>

This is the query I've been trying to get to work with it

$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => array( 'post-format-aside', 'post-format-image' ),
            'operator' => 'NOT IN'
        )
    )
);
$query = new WP_Query( $args );

1 Answer 1

-1
$args=array(
    'paged'=>$paged, //Pulls the paged function into the query
    'posts_per_page'=> 4, //Limits the amount of posts on each page
    'post_type'=>'post_type', //Set your allowed post types here
    'orderby' => 'title',
    'order' => 'ASC'
);

query_posts($args);

For more reference refer this.

You can pass the allowed post_type array to post_type argument in arguments array.

1
  • Wouldn't this only work for post types and not post formats? I need to exclude all formats but the standard post format
    – Jae
    Commented Nov 6, 2012 at 16:51

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.