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
$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;
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/
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;
?>
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
Works like a charm – thanks keesiemeijer!