我想在外部頁面上調用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語句運行它告訴我,該變量空或不顯示,因爲「測試」顯示。
此外,我刪除了if/else語句,只是嘗試foreach循環來查看我得到的確切錯誤。
這是錯誤
Invalid argument supplied for foreach() in /home2/asdf/public_html/community/library/asdfTab/Listener.php, line 54:
我也試圖與WP_Query同樣的事情,在變量正在返回空的,所以我不知道確切的問題是什麼,但似乎他們是無法檢索我請求的帖子。
請不要做出錯誤的建議。他的WordPress安裝可能沒問題。他只是不正確地使用它,這導致他的EXTERNAL頁面出現錯誤。 –