我有一个AJAX调用来填充下拉列表:
function get_select_companies()
{
var t_id = $(\'select#select-product_types\').val();
if( t_id == -1 )
{
$(\'#ajax-loader\').hide();
$(\'#select-manufacturers\').hide();
}
else
{
$(\'#ajax-loader\').show();
$(\'#select-manufacturers\').hide();
$(\'#select-manufacturers option\').remove();
jQuery.ajax(
{
url: \'/wp-admin/admin-ajax.php\',
type: \'POST\',
data: (
{
action: \'px_get_select_companies\',
type_id: t_id
}),
dataType: \'JSON\',
success: function(data)
{
$(\'#select-manufacturers\').append(data);
$(\'#ajax-loader\').hide();
$(\'#select-manufacturers\').show();
}
});
}
}
然后在我的函数中有这个php函数。php文件
function px_get_select_companies()
{
$args = array(
\'post_type\' => \'products\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'product_types\',
\'field\' => \'id\',
\'terms\' => array( $_POST[\'type_id\'] )
),
)
);
$query = new WP_Query( $args );
while( $query->have_posts() ) : $query->the_post();
if( $query->post->ID != 1 ) :
$terms[] = get_the_terms( $query->post->ID, \'manufacturers\' );
endif;
endwhile;
foreach( $terms as $term ) :
foreach( $term as $ID ) :
$term_IDs[] = $ID->term_id;
endforeach;
endforeach;
$term_IDs = array_unique( $term_IDs );
$output = \'<option value="0" selected="selected">--- Επέλεξε Εταιρεία ---</option>\';
foreach( $term_IDs as $ID ) :
$term = get_term_by( \'id\', $ID, \'manufacturers\' );
$output .= \'<option value="\' . $term->term_id . \'">\' . $term->name . \'</option>\';
endforeach;
wp_reset_postdata();
$output=json_encode($output);
if(is_array($output)){
print_r($output);
}
else
{
echo $output;
}
die;
}
问题是我得到了一个无休止的旋转器,因为它不会返回任何结果。如果我将posts\\u per\\u page更改为100或更少,它将按预期工作。有人知道它为什么这样做吗?
谢谢