在那儿我有想要显示的数据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;
}

在这里我想显示数据:

javascript - 如何在相同的post id wordpress中显示postmeta键和值(JSON数据)-LMLPHP

元数据具有相同的帖子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);

09-11 17:50
查看更多