如何在搜索结果上添加标签?请检查图片以供参考我只想将两个结果与特定标题分开,我怎样才能实现这一点?
<script>
/* globals global */
jQuery(function($) {
var searchRequest;
$('.search-autocomplete').autoComplete({
minChars: 2,
source: function(term, suggest) {
try {
searchRequest.abort();
} catch (e) {}
searchRequest = $.getJSON(global.ajax, {
q: term,
action: 'search_site'
}, function(res) {
//console.log(res.data);
var suggestions = [];
res.data.forEach(x => {
console.log(x);
if (~x.post_title.toLowerCase().indexOf(term)) {
suggestions.push(x.post_title);
} else if (~x.post_status.toLowerCase().indexOf(term)) {
suggestions.push(x.post_title);
}
suggest(suggestions);
});
// for (i=0;i<res.data.length;i++)
// if (~res.data.post_title[i].toLowerCase().indexOf(term)) suggestions.push(res.data.post_title[i]);
// suggest(suggestions);
});
}
});
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-autocomplete/1.0.7/jquery.auto-complete.css" rel="stylesheet"/>
<form role="search" method="get" id="searchform" action="http://localhost/gigant-live/">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" autocomplete="off" value="" name="s" class="form-control search-autocomplete" id="s" placeholder="My Search form" />
<input type="submit" id="searchsubmit" value="Search" />
<input type="hidden" name="post_type" value="product" />
</div>
</form>
素胚勾勒不出你
PIPIONE
缥缈止盈
相关分类