[英]Add php code inside the function add_shortcode in functions.php Wordpress
[英]How do I resolve this error with add_shortcode and wpdb on in functions.php on my Wordpress site?
我正在编写一个 function ,我想从简码中调用它并从他们的 ID 中返回用户的名称。 我已将此代码添加到我的 functions.php 文件中。
function get_name_result() {
global $wpdb;
$dbresult = $wpdb->get_results ("SELECT name FROM person WHERE id = 2",OBJECT);
return $dbresult;
}
add_shortcode('get_name', 'get_name_result');
?>
当放置在页面上时,短代码返回“array”而不是“Jim”。 关于我要去哪里错的任何建议?
如果您只期望 1 条记录(假设是这样,因为您在 where 语句中使用了 id),您可以将其返回
返回$dbresult[0]->名称;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.