Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress Wp_query object with 2 posts prints only one
    primarykey
    data
    text
    <p>I need to display the latest post from 3 categories and two posts from this last one with another HTML formatting. The problem is the last category prints only one post and stops with a <code>var_dump()</code> on the object I can see the two posts.</p> <p>Check the functions here:</p> <pre><code>function destaques( $atts ) { extract( shortcode_atts( array( 'id' =&gt; 0, ), $atts ) ); $id = array(6,16,10,4); $posts = array(); $nomesCat = array(); foreach ($id as $key =&gt; $value) { if ($value == 4){ //this is the categorie with two posts $posts[] = new WP_Query( array('posts_per_page' =&gt; 2, 'category__in' =&gt; array($value))); } else { $posts[] = new WP_Query( array('posts_per_page' =&gt; 1, 'category__in' =&gt; array($value))); } $nomesCat[] = get_category($value); } $html = '&lt;ul class="destaques"&gt;'; foreach ($posts as $key =&gt; $value) { if ($value-&gt;have_posts()){ while($value-&gt;have_posts()){ $value-&gt;the_post(); if ($nomesCat[$key]-&gt;cat_name == 'Colunistas') { // check for the categorie name, then call another // function, passing the wp_query object $html .= auxiliarColunistas($value); break; } else { //lots of html formatting code $html .= '&lt;/li&gt;'; } } } } $html .= '&lt;/ul&gt;'; return $html; </code></pre> <p>This is the helper function:</p> <pre><code>function auxiliarColunistas ($posts) { $html = '&lt;li class="last"&gt;'; /*var_dump($posts); this returns two posts! die;*/ $html .= '&lt;h2&gt;Colunistas&lt;/h2&gt;'; if ($posts-&gt;have_posts()){ while ($posts-&gt;have_posts()) { $posts-&gt;the_post(); //more html formatting code } } $html .= '&lt;/li&gt;'; return $html; } </code></pre> <p>Why does the loop print just one post and stops?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload