我想使用開關按鈕運行短代碼。如果開關處於「開」狀態,我稱之爲短碼,如果它處於「關」狀態,則打給另一個短碼。使用AJAX調用wordpress短代碼
作爲測試我打過電話,在與AJAX一個單一鏈路上點擊一個短代碼,它給了我這樣的:
文件「頁面recherche.php」:
<a href="" id="clicklien">CLICK HERE</a>
<script>
$("#clicklien").click(function(e){
e.preventDefault();
$.ajax({
url: 'http://www.capitainebar.com/wp-content/themes/Capitaine-Bar/shortcode-recherche.php',
success: function (data) {
// this is executed when ajax call finished well
console.log('content of the executed page: ' + data);
$('body').append(data);
},
error: function (xhr, status, error) {
// executed if something went wrong during call
if (xhr.status > 0) alert('got error: ' + status); // status 0 - when load is interrupted
}
});
});
</script
文件名爲是「shortcode-recherche.php」:
<?php echo do_shortcode('[search-form id="1" showall="1"]'); ?>
結果是致命錯誤。就好像代碼運行在「shortcode-recherche.php」而不是「page-recherche.php」中。
請注意,如果我不通過AJAX調用將短代碼直接寫入我的頁面,短代碼工作正常。
你可以看到the result here
你能發佈你收到的錯誤嗎? – Dez 2014-09-26 23:00:44
致命錯誤:調用未定義的函數do_shortcode()在/homepages/1/d543902707/htdocs/wp-content/themes/Capitaine-Bar/shortcode-recherche.php在線1 – 2014-09-26 23:38:03