WP_QUERY According To Post Format

Share Now

Share on facebook
Share on pinterest
Share on twitter
Share on linkedin
Share on email

Code Example:
Show Post where post format ‘Audio’ & Video


<?php 
  $paged = get_query_var( "paged" )?get_query_var( "paged" ) : 1;
  $posts_per_page = -1;
  $_p = new WP_Query(array(
  	'posts_per_page'	=> $posts_per_page,
  	'paged'				=> $paged,
  	'tax_query'			=> array(
  
  		'relation' => 'AND',
  		array(
  			'taxonomy' => 'post_format',
  			'field'	   => 'slug',
  			'terms'	   => array(
                        'post-format-audio',
                        'post-format-video'
                  )
  		)
  
  	)
  ));
  
  
  while( $_p->have_posts() ):
  $_p->the_post();
  ?>


//POST TITLE
<h3><a href="<?php the_permalink(  ); ?>">
  <?php the_title(  ); ?>
  </a>
</h3>



<?php
  endwhile;
  wp_reset_query();
?>








***Code Example:
Show Post where post format is not ‘Audio’ & Video


<?php 
  $paged = get_query_var( "paged" )?get_query_var( "paged" ) : 1;
  $posts_per_page = -1;
  $_p = new WP_Query(array(
  	'posts_per_page'	=> $posts_per_page,
  	'paged'				=> $paged,
  	'tax_query'			=> array(
  
  		'relation' => 'AND',
  		array(
  			'taxonomy' => 'post_format',
  			'field'	   => 'slug',
  			'terms'	   => array(
                        'post-format-audio',
                        'post-format-video'
                  ),
            'operator'=>"NOT IN"
  		)
  
  	)
  ));
  
  
  while( $_p->have_posts() ):
  $_p->the_post();
  ?>


//POST TITLE
<h3><a href="<?php the_permalink(  ); ?>">
  <?php the_title(  ); ?>
  </a>
</h3>



<?php
  endwhile;
  wp_reset_query();
?>








Nahid Mahamud

Nahid Mahamud

Web Developer | Graphic Designer | WordPress & Woo-commerce Expert