2017-06-06 67 views
0

我有兩個下拉框,一個帶有自定義分類法,另一個帶有自定義帖子,位於當前所選分類法下。爲此我寫了一個on-change函數。我有一些問題,顯示出把 它的顯示輸出這樣無法在wordpress中顯示選擇框作爲ajax響應

8Associate<select class="form-control" name="upload_designation" id="upload_designation" > 

<option value="">Select Designation</option><option value=""></option></select> 

,而不是

<select class="form-control" name="upload_designation" id="upload_designation" > 

<option value="">Select Designation</option> 
<option value="8">Associate</option></select> 

我在這裏 張貼我的變化功能好心幫我找出這個問題

function change_desgination() { 
$post_val=explode("_",$_POST['id']); 
$id=$post_val[0]; 
$taxonomy_name=$post_val[1]; 


$out='<select class="form-control" name="upload_designation" id="upload_designation" > 
<option value="">Select Designation</option>'; 

    $args = array(
    'post_type' => 'designation', 
    'post_status' => 'publish', 
    'posts_per_page' => -1, 
    'tax_query' => array(
     array(
      'taxonomy' => 'domain', 
      'field' => 'slug', 
      'terms' => $taxonomy_name 
     ) 
    ) 
); 
$the_query = new WP_Query($args); 

while ($the_query->have_posts()) : $the_query->the_post(); 
$theid=the_ID(); 
$thetitle=the_title(); 

    $out.='<option value="'.$theid.'">'.$thetitle.'</option>'; 

endwhile; 
    $out.='</select>'; 
    die($out); 
} 

可能是問題與報價。任何人都請幫我找到問題。提前致謝。

+0

$ thetitle = the_title();檢查$ thetitle值? –

+0

@Dinesh the_title()值正在改正它的'the_title()= Associate'和'the_ID()= 8'這些值即將到來,但不在

回答

0

檢查你的代碼,我建議你使用foreach循環,而不是同時如下

<?php 

$out='<select class="form-control" name="upload_designation" id="upload_designation" > 
<option value="">Select Designation</option>'; 

$array = array('one','two','three','four'); 

foreach ($array as $key => $value) { 
    $out.='<option value="'.$key.'">'.$value.'</option>'; 
} 
    $out.='</select>'; 
    die($out); 
?> 

用代碼顯示陣列