【发布时间】:2016-01-18 16:31:01
【问题描述】:
所以,我有以下帖子循环来显示帖子(wp functions.php)。
global $post;
$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC'
);
$loop = new WP_Query( $args );
$id = get_the_ID();
while ( $loop->have_posts() ) : $loop->the_post();
$my_post['sample_id'] = get_the_title( $id );
endwhile;
wp_reset_postdata();
我需要在一个值数组中包含帖子的标题(例如 array[title1, title2, title3])。
但是,它只选择一个标题。
如何使$my_post 变量可以具有三个值?
(换句话说,我只想将三个标题作为变量的结果)
编辑:
....
while ( $loop->have_posts() ) : $loop->the_post();
array_push($titleArray, get_the_title($id));
endwhile;
$tag_post['sample_id'] = $titleArray;
echo json_encode($tag_post);
wp_reset_postdata();
exit;
【问题讨论】: