WP_Query don't return posts when call from a classA to classB
-
I have two classes
class A {}andclass B {}. And i hasWP_Queryloop withinclass A {}as belowclass A { static function YPE_lastposts($divide_to, $col) { $my_query = 'showposts = '.$divide_to; $my_query = new WP_Query($my_query); while ($my_query->have_posts()) : $my_query->the_post(); $item_output .= '<div class="col-sm-'.$col.'">'; $item_output .= get_the_title(); $item_output .= '</div>'; endwhile; wp_reset_postdata(); } }And i have
class B {}as below and called above method within it but don’t return any post fromWP_Queryloopclass B extend C { public function start_el() { if (!empty($item->divideto_4)) { $col = 3; $divide_to = 12 / $col; YPE_Bootstrap_Navbar_Content::YPE_lastposts($divide_to, $col); } } }When put WP_Query loop directly within
start_el()method work and return posts.
But when callWP_Queryloop from other class not work Why?
The topic ‘WP_Query don't return posts when call from a classA to classB’ is closed to new replies.