Title: Simple Query Confusion!
Last modified: August 20, 2016

---

# Simple Query Confusion!

 *  [brian317](https://wordpress.org/support/users/brian317/)
 * (@brian317)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/simple-query-confusion/)
 * Just trying to get a single random post of the post type ‘quote’ to come up in
   my sidebar, pretty common right!? Well I had something working with pulling all
   quotes using post_type code, but I’ve broken it with this:
 *     ```
       $quotesQuery = new WP_Query( array ( 'orderby' => 'rand', 'posts_per_page' => '1' ) );
   
       				while ( $quotesQuery->have_posts() ) : $quotesQuery->the_post();
   
       					if(has_post_format( 'quote' )) {
       					print "<div class='testimonial'>";
       						print "<p>";
       						the_content();
       						print "</p>";
       						print "<p class='testimonial_author'>";
       						the_title();
       						print "</p>";
       					print "</div>";
       					}
       				endwhile;
       ```
   
 * What am I blind to?
 * thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Jay](https://wordpress.org/support/users/phyrax/)
 * (@phyrax)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/simple-query-confusion/#post-2480557)
 * Are you confusing “post formats” with “post types”? To clarify, you’re pulling
   a ‘quote’ post type, not format, according to your description. Therefore you
   should use the ‘post_type’ argument in the WP_Query class. More info here > [Type & Status Parameters ](http://codex.wordpress.org/Class_Reference/WP_Query#Type_.26_Status_Parameters)
 *     ```
       $quotesQuery = new WP_Query( array ( 'orderby' => 'rand', 'posts_per_page' => '1', 'post_type' => 'quote') );
   
       				while ( $quotesQuery->have_posts() ) : $quotesQuery->the_post();
       					print "<div class='testimonial'>";
       						print "<p>";
       						the_content();
       						print "</p>";
       						print "<p class='testimonial_author'>";
       						the_title();
       						print "</p>";
       					print "</div>";
       				endwhile;
       ```
   
 *  Thread Starter [brian317](https://wordpress.org/support/users/brian317/)
 * (@brian317)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/simple-query-confusion/#post-2480638)
 * Hi Jerry, thanks for the reply – that isn’t working for me, this is what I had
   before, which displays all my posts that are of the post format quote. (that’s
   what I really meant – not ‘type’)
 *     ```
       $future_query = new WP_Query('category_name=Sidebar&posts_per_page=10');
       			$quoteArrayLast = array( array('','') );
       			$aR = 0; 
   
       			while ( $future_query->have_posts() ) : $future_query->the_post();
       				$aS = 0;
       				if(has_post_format( 'quote' )) {
       						$quoteArrayLast[$aR][0] = "".get_the_content()."";
       						$quoteArrayLast[$aS][1] = "".get_the_title()."";
       						$aR++;
       					}
   
       				//print_r($post);
   
       			endwhile; 
   
       				foreach($quoteArrayLast as $tempQuote) {
   
       					print "<div class='testimonial'>";
       						print "<p>".$tempQuote[0]."</p>";
       						print "<p class='testimonial_author'>".$tempQuote[1]."</p>";
       					print "</div>";
   
       				}
       ```
   
 * This is pulling the quotes, although the 2nd one is not showing the title as 
   the author for some reason, but the first one displays correctly…
 * And for some reason I can’t bring the number down with the “posts per page”, 
   just want to display 1, and for it to be random!
 * Its going to appear on this page: [http://alfacomputer.com/home-2/](http://alfacomputer.com/home-2/)
 * This is what I thought would work perfect, but it displays the most recent post,
   not even a quote.
 *     ```
       $quotesQuery = new WP_Query(
       					array (
       						'has_post_format' => 'quote',
       						//'orderby' => 'rand',
       						'posts_per_page' => '1' )
       						 );
   
       				while ( $quotesQuery->have_posts() ) : $quotesQuery->the_post();
       					print "<div class='testimonial'>";
       						print "<p>";
       						the_content();
       						print "</p>";
       						print "<p class='testimonial_author'>";
       						the_title();
       						print "</p>";
       					print "</div>";
       				endwhile;
   
       				?>
       ```
   
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/simple-query-confusion/#post-2480647)
 * Try it with this:
 *     ```
       $args = array(
         'orderby' => 'rand',
       	'posts_per_page' => 1,
       	'tax_query' => array(
       		array(
       			'taxonomy' => 'post_format',
       			'field' => 'slug',
       			'terms' => array( 'post-format-quote' )
       		)
       	)
       );
       $quotesQuery = new WP_Query( $args );
       ```
   
 * [https://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters](https://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters)
 *  Thread Starter [brian317](https://wordpress.org/support/users/brian317/)
 * (@brian317)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/simple-query-confusion/#post-2480654)
 * Works like a charm – thanks keesiemeijer!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Simple Query Confusion!’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [brian317](https://wordpress.org/support/users/brian317/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/simple-query-confusion/#post-2480654)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
