WordPress无法在自身外工作

时间:2013-07-20 05:05:36

标签: php wordpress

我正在尝试在外部页面上调用WordPress功能。我已经摆脱了第一个遇到错误的障碍:

This Plugin Requires WordPress 3.1+ or Greater: Activation Stopped!

通过字面上禁用我网站上的所有内容。

现在我面临另一个小问题。

我已添加此要求声明:<?php require('/path/to/my/wp-blog-header.php'); ?>

我收到以下错误。当然,这个要求声明不属于任何一类。

Fatal error: Call to a member function main() on a non-object in /home2/phanime/public_html/wp-includes/functions.php on line 781

在询问之前我也环顾四周,并且人们说要添加以下行:global $wpdb;但它没有帮助,错误仍然存​​在。

我也试过简单地放一行代码(必需的语句),问题仍然存在。

根据某人的建议,我会更新此问题。我有初始化工作,但现在我无法使用WP_Query或get_posts,他们不返回任何东西。例如,我试过这段代码

$testingQuery = get_posts(array(
            'post_type' => 'anime',
            'order' => 'date'
            ));

然后使用if / else语句检查变量是否为空

        if ($testingQuery) {

            foreach( $testingQuery as $post ) : setup_postdata($post);

                $contents .= '<li id="ourTab" class="profileContent">
                            <div class="section">AnimeList Coming soon.</div>
                            </li>';

                            $contents .= get_the_title(); 

                    endforeach;

        } else { 



                $contents .= '<li id="ourTab" class="profileContent">
                            <div class="section">Test</div>
                            </li>';





        }

在这种情况下,运行else语句,告诉我该变量为空或不存在,因为显示“Test”。

此外,我删除了if / else语句,只是尝试使用foreach循环来查看我得到的确切错误。

这就是错误

Invalid argument supplied for foreach() in /home2/asdf/public_html/community/library/asdfTab/Listener.php, line 54:

我也尝试过与WP_Query相同的事情并且变量返回空,所以我不知道确切的问题是什么,但似乎他们无法检索我要求的帖子。

3 个答案:

答案 0 :(得分:0)

你需要在调用任何函数之前初始化WordPress。 在调用任何函数之前,请尝试将wp-config.php放入外部页面。

答案 1 :(得分:0)

将以下内容放在外部脚本的开头

<?php
require_once("path/to/wp-load.php");

然后wp将自举,你可以调用其他函数

答案 2 :(得分:-2)

看起来你需要reinstall Wordpress在做之前备份你的东西。