WordPress主题开发:调用未定义的函数WP_Query()

我正在开发自己的Wordpress主题, 并且在尝试获取自定义帖子(“事件”)时, 在我的functions.php文件中存在此问题”对未定义函数WP_Query()的调用”。

我已经尝试添加include(‘wp-load.php’), 但没有进行任何更改。

有人有同样的问题吗?已经进行了一些研究, 但没有找到解决我问题的任何方法。

这是我的简单代码:

$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";

非常感谢你的帮助!

吉莲


#1


在调用WP_Query之前, 你应该使用new。

更改:

$result = WP_Query( $argsEvents );

至:

$result = new WP_Query( $argsEvents );

来源:

https://www.srcmini02.com/66771.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37025.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?