我试图在自定义模板中使用ajax函数来检索帖子的自定义字段,以显示帖子概述。获取自定义字段是可行的,但获取永久链接不是可行的。我正在获取永久链接,以便可以链接到帖子。当我使用get_permalink()
是第一个字母。另外,请注意,我使用AJAX返回一个数组。我不知道这是否是问题所在。
非常感谢你。
猎人
密码
function ajax_action_stuff()
{
$post_id = $_POST[\'post_id\']; // getting variables from ajax post
$get_plane_custom = get_post_custom($post_id);
$condition = $get_plane_custom[\'Condition\'];
$rules = $get_plane_custom[\'Flight Rules\'];
$manufacturer = $get_plane_custom[\'Manufacturer\'];
$model = $get_plane_custom[\'Model\'];
$price = $get_plane_custom[\'Price\'];
$lease = $get_plane_custom[\'To Lease\'];
$time = $get_plane_custom[\'Total Time\'];
$year = $get_plane_custom[\'Year\'];
$permalink = get_permalink($post_id);
$plane_details = array("condition" => $condition, "rules" => $rules, "manufacturer" => $manufacturer, "model" => $model, "price" => $price, "lease" => $lease, "time" => $time, "year" => $year, "link" => $permalink);
foreach($plane_details as $key => $value)
{
echo $value[0] . "|";
}
die();
}
最合适的回答,由SO网友:tfrommen 整理而成
数组的索引“link”的值$plane_details
是字符串,因此$value[0]
只给你第一个字母。
只需更换$value[0]
通过$value
一切都会好起来的。
无论如何,为什么要以这种方式引用值?