• I have two classes class A {} and class B {} . And i has WP_Query loop within class A {} as below

    class 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 from WP_Query loop

    class 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 call WP_Query loop 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.