What would prevent WP_Query()
from working inside a class method?
class MyClass
{
function __construct()
{
$this->myFunc();
}
public function myFunc()
{
global $post, $wp_query;
$args_ = array(
'post_type' => 'post',
'posts_per_page' => -1,
'suppress_filters' => false
);
$the_query = new WP_Query( $args_ ); // doesn't work
/*...*/
}
}
It all works perfectly outside of the class, I can’t find a logical reason as to why it does not work inside.
Update:
The displayed error is
Fatal error: Call to undefined function is_user_logged_in() in
/home/oricoil/public_html/roofdagan1/wp-includes/query.php on line
3174
Could it be a conflict with some other variable, declared inside your class?
EDIT
The solution (see the comments) was changing
to
I met the same problems. My solution is add a back slash and it works now.