无法在wordpress中显示选择框作为ajax响应

问题描述:

我有两个下拉框,一个带有自定义分类法,另一个带有自定义帖子,位于当前所选分类法下。为此我写了一个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'这些值即将到来,但不在

的问题是与

$theid=the_ID(); 
$thetitle=the_title(); 
更换您的数据

the_ID() and the_title() will ec ho的值为 ,其中get_the_ID();get_the_title();将以字符串形式返回值。 所以我用

$theid=get_the_ID(); 
$thetitle=get_the_title(); 

参考链接

https://wordpress.stackexchange.com/questions/48523/get-title-of-post-without-using-the-title

而且

https://developer.wordpress.org/reference/functions/get_the_id/

检查你的代码,我建议你使用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); 
?> 

用代码显示阵列