gpt4 book ai didi

javascript - 如何在同一帖子 ID wordpress(JSON 数据)中显示 postmeta 键和值

转载 作者:行者123 更新时间:2023-12-02 05:40:52 25 4
gpt4 key购买 nike

那里有我要显示的后元数据

$command = $_GET['command'];
switch ($command) {
case 'list_product':

$loop = new WP_Query(
array(
'post_type' => 'product'
// 'showposts' => 4,
// 'meta_key' => '_sale_price',
// 'meta_value' => '0',
// 'meta_compare' => '>=',
)
);
if($loop->have_posts()) :

$data = array( "api_status" => 1, "api_message" => "success");
while ( $loop->have_posts() ) : $loop->the_post();

$data[] = array("id" => get_the_ID(),
"post_name" => get_the_title(),
"post_meta" => get_post_meta(get_the_ID());

endwhile;


echo json_encode($data);
break;
}

在那里我想显示数据:

enter image description here

元数据具有相同的帖子 ID 数据,

我想在内部细节中循环数据,请人帮助我或告诉我我需要改进哪些代码以便我的代码正常工作?

最佳答案

元数据存储在 wp_postmeta 表中。使用 json_encode。

您可以通过$meta = get_post_meta( get_the_ID() );获取元数据

请检查以下代码。

if($loop->have_posts()) :

$data = array( "api_status" => 1, "api_message" => "success");
while ( $loop->have_posts() ) : $loop->the_post();

$data[] = array("id" => get_the_ID(),
"post_name" => get_the_title(),
"post_meta" => get_post_meta(get_the_ID());

endwhile;


echo json_encode($data);

关于javascript - 如何在同一帖子 ID wordpress(JSON 数据)中显示 postmeta 键和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40187629/

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