gpt4 book ai didi

javascript - 将函数传递给 .load php (wordpress)

转载 作者:行者123 更新时间:2023-11-28 04:35:55 24 4
gpt4 key购买 nike

所以我有一个包含此内容的 single.php。

    $('#ajax').load('<?php echo get_template_directory_uri(); ?>/test.php?choices=<?php echo $post_id; ?>');

这会将 test.php 加载到其中

     <div id="ajax"></div>

test.php 完美加载。但我想使用functions.php中的函数在single.php中我可以执行functions.php中的任何功能。因为这是 WordPress 标准。

但是当我尝试在 test.php 中使用它的函数时,出现错误。这是错误

  Fatal error: Call to undefined function add_theme_support() in /customers/9/9/c/papercraftplaza.com/httpd.www/wp-content/themes/papercraftplazaV2/functions.php on line 2

这就是 test.php 中的所有内容。我想使用的功能目前是评论。我如何包含它以便我可以使用我的函数?

  <?php
include "functions.php";

$_GET['choices'];
$passedvar = reset($_GET);

//setPostDownloads($passedvar);
//echo getPostDownloads($passedvar);

?>
<p>You downloaded papercraft: <?php echo reset($_GET); ?></p>

最佳答案

显然我必须包含 wp-load.php这应该取代包含函数。现在可以了!

  $path = preg_replace('/wp-content.*$/','',__DIR__);
$path = preg_replace('/wp-content(?!.*wp-content).*/','',__DIR__);
include($path.'wp-load.php');

关于javascript - 将函数传递给 .load php (wordpress),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44210097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com