| Server IP : 104.129.129.72 / Your IP : 216.73.216.229 Web Server : LiteSpeed System : Linux 123answers 5.15.0-143-generic #153-Ubuntu SMP Fri Jun 13 19:10:45 UTC 2025 x86_64 User : answe8064 ( 1002) PHP Version : 8.2.28 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/123answers.ca/public_html/saskatoon/wp-content/themes/directorytheme/npm/ |
Upload File : |
<?php
/* Searching a listing from home page searchbar section.*/
// add the ajax fetch js
add_action( 'wp_footer', 'listing_ajax_fetch' );
function listing_ajax_fetch() {
?>
<script type="text/javascript">
var sseen = {};
jQuery('#single_listing_form .listing_address,#home_search .listing_address').each(function() {
var txt = jQuery(this).text();
if (sseen[txt])
jQuery(this).remove();
else
sseen[txt] = true;
});
jQuery("#listing_category").change(function(){
var scattext = jQuery(this).children("option:selected").val();
scattext1 = encodeURIComponent(scattext);
jQuery(this).parent().parent().find('#s_listing_category').val(scattext1);
jQuery(this).parent().parent().find('button.btn').text(scattext);
});
jQuery('#single_listing_form button.reset-btn,#home_search button.reset-btn').click(function(){
jQuery('.listing_keyword').val("");
jQuery('#listing_category').prop('selectedIndex',0);
jQuery('#s_listing_category').val("");
jQuery('#single_listing_form #listing_address,#home_search #listing_address').text("Search by: Address");
jQuery('#listing_address').val("");
});
jQuery(window).bind('load', function() {
jQuery('#single_listing_form .dropdown-address').click(function(){
var saddresstext = jQuery(this).text();
jQuery(this).parent().parent().find('#s_listing_address').val(saddresstext);
jQuery(this).parent().parent().find('button.btn').text(saddresstext);
});
});
jQuery("#single_listing_form").submit(function(event) {
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
var my_listing = jQuery('#listing_keyword').val();
var listing_address = jQuery('#listing_address').val();
var listing_category = jQuery('#listing_category').val();
my_listing = my_listing.replace(/[^a-z0-9\s]/gi, ' ').replace(/[_\s]/g, ' ');
jQuery('#loading-icon,button .s-spinner').show();
jQuery.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'post',
data: { action: 'listing_fetch', s_listing_category : listing_category, s_listing_keyword : my_listing, s_listing_address : listing_address },
success: function(data) {
jQuery('#listing_ajax').html( data );
var divs = jQuery("#listing_ajax .col-lg-4");
for(var i = 0; i < divs.length; i+=3) {
divs.slice(i, i+3).wrapAll("<div class='row'></div>");
}
},
complete: function(){
jQuery('#loading-icon,button .s-spinner').hide();
}
});
});
//end form_listing
//Start Business suggestion list
jQuery(function () {
var keys = [];
var dataList = jQuery('.srldiv input').each(function(){
var dataSrc=jQuery(this).attr("data-businame");
keys.push(dataSrc.replace("’",""));
});
jQuery("#listing_keyword").autocomplete({
source: keys
});
});
//End Business suggestion list
jQuery(function () {
var addkeys = [];
var dataList = jQuery('.sbaddress input').each(function(){
var dataSrc=jQuery(this).attr("data-address");
addkeys.push(dataSrc);
});
jQuery("#listing_address").autocomplete({
source:addkeys
});
});
jQuery(function () {
var addkeys = [];
var dataList = jQuery('.sbaddress1 input').each(function(){
var dataSrc=jQuery(this).attr("data-address");
addkeys.push(dataSrc);
});
jQuery("#listing_address").autocomplete({
source:addkeys
});
});
</script>
<?php
}
function theme_autocomplete_js() {
$args = array(
'post_type' => 'listings',
'post_status' => 'publish',
'posts_per_page' => -1 // all posts
);
$posts = get_posts( $args );
if( $posts ) :
foreach( $posts as $k => $post ) {
$source[$k]['ID'] = $post->ID;
$source[$k]['label'] = $post->post_title; // The name of the post
$source[$k]['permalink'] = get_permalink( $post->ID );
}
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var posts = <?php echo json_encode( array_values( $source ) ); ?>;
jQuery('#s_listing_keyword').autocomplete({
source: posts,
minLength: 2,
select: function(event, ui) {
var permalink = ui.item.permalink; // Get permalink from the datasource
window.location.replace(permalink);
}
});
});
</script>
<?php
endif;
}
add_action( 'wp_footer', 'theme_autocomplete_js' );
// the ajax function
add_action('wp_ajax_listing_fetch' , 'listing_fetch');
add_action('wp_ajax_nopriv_listing_fetch','listing_fetch');
function listing_fetch(){
global $choices_array1;
$main_args = array(
'posts_per_page' => -1,
's' => sanitize_text_field(esc_attr($_POST['s_listing_keyword'])),
'post_type' => 'listings',
'post_status' => 'publish',
'taxonomy'=>'listing-categories',
'term' => sanitize_text_field(esc_attr($_POST['s_listing_category']))
);
if(!empty($_POST['s_listing_category'])){
$main_args['tax_query'] = array(
array(
'taxonomy' => 'listing-categories',
'terms' => sanitize_text_field(esc_attr($_POST['s_listing_category'])),
'field' => 'slug',
)
);
}
if(!empty($_POST['s_listing_address'])){
$main_args['meta_query'] = array(
'relation' => 'AND',
array(
'key' => 'address',
'value' => sanitize_text_field(esc_attr($_POST['s_listing_address'])),
'compare' => 'LIKE'
)
);
}
$the_query = new WP_Query( $main_args);
if( $the_query->have_posts() ) :
while( $the_query->have_posts() ): $the_query->the_post();
$dtsimg=get_field('s_default_featured_image','option');
$ftdimg=get_the_post_thumbnail_url();
$post_img = get_field('featured_image');
if (is_numeric($post_img)) {
$post_img = wp_get_attachment_url($post_img);
} else {
$post_img = get_field('featured_image');
}
?>
<div class="col-lg-4">
<div class="featured-listing">
<div class="fl-img">
<div class="zioea">
<a href="<?php the_permalink(); ?>"><img src="<?php if(!empty($ftdimg)) { echo $ftdimg; } else if(!empty($post_img)) { echo $post_img; } else if(!empty($dtsimg)) { echo $dtsimg; } else{ echo bloginfo("template_url").'/images/Listing-Placeholder.png'; }?>" alt="<?php the_title(); ?>" class="img-fluid" /></a>
</div> <!-- zioea -->
<h3><a href="<?php the_permalink(); ?>" class="list-title-click"><?php the_title(); ?></a></h3>
<!-- category shortcode-->
<div class="col-md-12 category_display" style="padding : 0;">
<?php echo do_shortcode( '[displ_cat]' ); ?>
</div>
<?php if(get_field('listing_type') != $choices_array1[0] ) : ?>
<img src="<?php echo get_template_directory_uri(); ?>/images/star.png" class="premium-star" />
<?php endif; ?>
</div><!--fl-img-->
</div>
</div><!--col-->
<?php
endwhile;
wp_reset_postdata();
else :
?>
<p>No Listing Found.</p>
<?php
endif;
die();
}