CPT search NOT finding results from posts title

I have a search bar to search for CPT (properties) on a page and show results below it including on a map. The search works if searching by address but Its not working if I search by the post’s name/title.

I did not write this code so i’m looking for some insight.
Thanks.

<a href=”<?php echo get_site_url(null, ‘properties/’); ?>” class=”btn-orderby” style=”margin-left: 15px; margin-bottom: 18px;”>Reset</a>
<input type=”text” id=”searchby-name” placeholder=”Search By Name”>
<script type=”text/javascript”>

jQuery(document).ready(function($)

{

$(‘.property-filters’).change( function() {

var all_filters = [];

$(“.property-filters”).each(function(){

if($(this).val() != null && $(this).val().length > 0) all_filters.push($(this).val());

});

if(all_filters.length == 0){

window.location.href = “<?php echo get_site_url(null, ‘properties/’); ?>”;

} else {

var new_link = “<?php echo get_site_url(null, ‘/’); ?>?”+all_filters.join(“&”);

window.location.href = new_link;

}

});

});

</script>

<script>
jQuery(function($) {
// Search bar filter

let titles = []
$(‘#content-wrapper table tbody’).find(‘tr’).each(function(i, v) {
titles[i] = {
‘node’: v.outerHTML,
‘string’: $(v).find(‘a.heading-link.address_title’).text().trim().toLowerCase(),
‘lat’: $(v).data(‘lat’),
‘long’: $(v).data(‘lng’),
‘info’: “<div class=’map_div’><h4>”+ $(v).data(‘name’) +”</h4><a href='”+$(v).data(‘link’)+”‘>Go to Property</a></div>”,
}
})

console.log(titles);

$(‘#searchby-name’).on(‘keyup’, function() {
let q = $(this).val()
const tbl = $(‘#content-wrapper table tbody’).html(”)
locations = []
titles.filter(str => str.string.includes(q.toLowerCase())).map( x => {
tbl.append(x.node)
if(x.lat != ” && x.long != ”){
locations.push({
lat: x.lat,
lng: x.long,
info: x.info
})
}

})
initMap()
})
})
</script>

Read more here:: CPT search NOT finding results from posts title

Leave a Reply

Your email address will not be published. Required fields are marked *