如何在相同的帖子id wordpress(JSON数据)中显示postmeta键和值

Ada*_*ojo 2 javascript php wordpress json

在那里我有我想要显示的数据postmeta

$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;
}
Run Code Online (Sandbox Code Playgroud)

在那里我想显示数据:

在此输入图像描述

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

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

Ars*_* KV 5

元数据存储在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);
Run Code Online (Sandbox Code Playgroud)