0
function getProgramTourInfoByID(){
$data = getProgramTourInfoByCate();
//print_r($data);
foreach ($data as $key => $id) {
//echo($id);
$count =0;
while(have_rows('package_scd', $id)): the_row();
//if(get_sub_field('start_date') != null){
//echo $id."\r\n";
$array[$count] = array(
'id' => $id ,
'title' => get_the_title($id),
'url' => get_the_permalink($id),
'start' => get_sub_field('start_date'),
'end' => get_sub_field('end_date'),
'price_single_room' => get_sub_field('price_single_room'),
'price_adult' => get_sub_field('price_adult'),
'type' => "restricted",
);
$count ++;
endwhile;
}
$output = array('sourcename' => $array);
return $output;
}
function getProgramTourInfoByCate(){
$term_id = 3;
$args = array(
'post_type' => array('package'),
'posts_per_page' => -1,
'post_status' => array('publish') ,
'tax_query' => array(
array(
'taxonomy' => 'tour-categories',
'field' => 'id',
'terms' => $term_id,
'order'=>'DESC',
'orderby'=>'menu_order',
)
)
);
$query = new WP_Query($args);
if($query->have_posts()):
while($query->have_posts()):
$query->the_post();
$arr[] = get_the_ID();
endwhile;
return $arr;
endif;
}
ここに私のコードですが、間違った出力を返します。私はリターン$output = array('sourcename' => $array)
を持っているときWP REST APIのループでデータを返す方法は?
しかし:私はループwhile(have_rows('package_scd', $id)): the_row()
でecho $id
をテストするとき、それは右の出力であるデータベースからIDのすべてを返すがあります。私はIDの残りの部分が来ていない理由はわからない2つのID(24930と18367)だけが返されます。
whileループの中に '$ array'値を出力してチェックします。 – vel
私はprint_r($ array [$ count]);を持っています。私が望むようにすべてのデータを返します。 しかし、\t私が$ output = array( 'sourcename' => $ array);を返すとき。唯一の2つのID(24930と18367)が返されます。 – xDevelopers
'$ output = json-encode(array( 'sourcename' => $ array);)'を試しましたか? – vel