请告诉我我在做什么错在这里... PHP版本5.6.27使用wordpress 4.7.1。我将它创建为一个自定义插件。我的页面返回结果为“失败”,尝试了两个不同的页面标题,并且都返回“失败”,这告诉我它没有得到页面标题(位置)在函数中,并且函数失败返回else。PHP函数不返回键
$locations = array(
array(
'location' => 'About',
'telephone' => '0121 34838383',
'email' => '[email protected]'
)
);
function telephone_shortcode() {
global $locations;
$title = get_the_title();
$key = array_search($title, array_column($locations, 'location'));
if ($key)
return $locations[$key]['telephone'];
else
return 'fail';
}
add_shortcode('telephone', 'telephone_shortcode');
[电话] - 回报,如果被搜索的元素是在阵列中的第一个元素“失败”
太棒了!谢谢 :) –