gpt4 book ai didi

php - 从当前帖子获取记录

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

我正在尝试从当前帖子中获取 meta_value 字段的值。

<?php 
$cupost = $post->ID;
$registros = $wpdb->get_results( 'SELECT meta_value FROM auto_postmeta
WHERE post_id = $cupost AND meta_key="mg_game"');
echo $registros[0]->meta_value . "<br/>";
?>

它不显示来自 $registros 的回显。

但是如果我直接在查询中输入帖子的编号 (post_id = 7),它会显示 meta_value 的值。

最佳答案

你的这个:

<?php 
$cupost = $post->ID;//First check if this variable gets the id, i would echo the $cupost variable to check.
$registros = $wpdb->get_results( "SELECT meta_value FROM auto_postmeta WHERE post_id = ".$cupost." AND meta_key= 'mg_game' ");
echo $registros[0]->meta_value . "<br/>";
?>

您必须将查询字符串与 Php 变量连接起来

关于php - 从当前帖子获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32857093/

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