您好,自动完成预期源为array, URL string and function return
. 即使你付出JSON
那么它应该label and value
. 此处不存在,因为您只是输出get_terms
具有all
字段。
所以我建议只返回类别的名称。更改字段all
到names
将很好地工作。
<?php
$args = array(
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => false,
\'include\' => array(),
\'exclude\' => array(),
\'exclude_tree\' => array(),
\'number\' => \'\',
\'offset\' => \'\',
\'fields\' => \'names\',
\'name\' => \'\',
\'slug\' => \'\',
\'hierarchical\' => true,
\'search\' => \'\',
\'name__like\' => \'\',
\'description__like\' => \'\',
\'pad_counts\' => false,
\'get\' => \'\',
\'parent\' => \'0\',
\'childless\' => false,
\'cache_domain\' => \'core\',
\'update_term_meta_cache\' => true,
\'meta_query\' => \'\'
);
$phpArray = get_terms( \'listing_taxonomy\', $args );
?>
<script>
$(function() {
var availableTags = <?php echo json_encode($phpArray); ?>;
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>