admin管理员组文章数量:1323157
in there i have data postmeta i want to show
$mand = $_GET['mand'];
switch ($mand) {
case 'list_product':
$loop = new WP_Query(
array(
'post_type' => 'product'
// 'showposts' => 4,
// 'meta_key' => '_sale_price',
// 'meta_value' => '0',
// 'meta_pare' => '>=',
)
);
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;
}
in there i want to show data :
where the meta data have same post id data,
i want to loop the data in inside details, have someone help me or tell me what code need i improve so my code its work ?
in there i have data postmeta i want to show
$mand = $_GET['mand'];
switch ($mand) {
case 'list_product':
$loop = new WP_Query(
array(
'post_type' => 'product'
// 'showposts' => 4,
// 'meta_key' => '_sale_price',
// 'meta_value' => '0',
// 'meta_pare' => '>=',
)
);
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;
}
in there i want to show data :
where the meta data have same post id data,
i want to loop the data in inside details, have someone help me or tell me what code need i improve so my code its work ?
Share edited Oct 24, 2016 at 1:04 APSB asked Oct 22, 2016 at 2:06 APSBAPSB 5874 gold badges11 silver badges29 bronze badges 2- Wait, so you just wanna get this as JSON? – Jeremy Jackson Commented Oct 22, 2016 at 2:20
- sure.. have u can help me ? – APSB Commented Oct 22, 2016 at 3:36
3 Answers
Reset to default 5Meta data is storing in wp_postmeta table. Use json_encode.
You can fetch meta by $meta = get_post_meta( get_the_ID() );
Please check following code .
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);
If you just want your table data as json, then you just need to use json_encode()
http://php/manual/en/function.json-encode.php
You can try this
if( $loop->have_posts() ) :
$data = array( "api_status" => 1, "api_message" => "success");
$meta = array();
while ( $loop->have_posts() ) : $loop->the_post();
$meta[] = array(
"id" => get_the_ID(),
"post_name" => get_the_title(),
"_edit_lock" => get_post_meta( get_the_ID(), '_edit_lock', true ),
"_edit_last" => get_post_meta( get_the_ID(), '_edit_last', true ),
"username" => get_post_meta( get_the_ID(), 'username', true ),
"password" => get_post_meta( get_the_ID(), 'password', true ),
"email" => get_post_meta( get_the_ID(), 'email', true ),
"phone" => get_post_meta( get_the_ID(), 'phone', true ),
);
endwhile;
endif;
echo json_encode($meta);
本文标签: javascriptHow to display postmeta key and value in same post id wordpress (JSON data)Stack Overflow
版权声明:本文标题:javascript - How to display postmeta key and value in same post id wordpress (JSON data) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742140732a2422568.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论