[英]Wordpress theme development : Call to undefined function WP_Query()
I'm developing my own Wordpress theme and I have this issue " Call to undefined function WP_Query() " with my functions.php file while trying to get my Custom posts ("event"). 我正在开发自己的Wordpress主题,并且在尝试获取我的自定义帖子(“事件”)时,在我的functions.php文件中存在此问题“ 调用未定义的函数WP_Query() ”。
I already tried to add include('wp-load.php') but did not change anything. 我已经尝试添加include('wp-load.php'),但没有进行任何更改。
Did anyone already have the same issue ? 有人有同样的问题吗? Already did some researches but did not find anything that solved my problem. 已经进行了一些研究,但没有找到解决我问题的任何方法。
Here is my simple code : 这是我的简单代码:
$argsEvents = array('post_type' => 'event', 'posts_per_page' => '-1');
$result = WP_Query( $argsEvents );
if ( $result->have_posts() ) {
echo '<ul>';
while ( $result->have_posts() ) {
$result->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
wp_reset_postdata();
} else echo "No data";
Thanks a lot for you help! 非常感谢您的帮助!
Gillian 吉莲
You should be using new before calling WP_Query . 您应该在调用WP_Query之前使用new 。
Change: 更改:
$result = WP_Query( $argsEvents );
To: 至:
$result = new WP_Query( $argsEvents );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.