Deprecated: Creation of dynamic property PH_Blmexport::$id is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-blm-export/propertyhive-blm-export.php on line 49
Deprecated: Creation of dynamic property PH_Blmexport::$label is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-blm-export/propertyhive-blm-export.php on line 50
Deprecated: Creation of dynamic property PH_Infinite_Scroll::$id is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-infinite-scroll/propertyhive-infinite-scroll.php on line 49
Deprecated: Creation of dynamic property PH_Infinite_Scroll::$label is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-infinite-scroll/propertyhive-infinite-scroll.php on line 50
Deprecated: Creation of dynamic property PH_Location_Autocomplete::$id is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-location-autocomplete/propertyhive-location-autocomplete.php on line 49
Deprecated: Creation of dynamic property PH_Location_Autocomplete::$label is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-location-autocomplete/propertyhive-location-autocomplete.php on line 50
Deprecated: Creation of dynamic property PH_Map_Search::$id is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-map-search/propertyhive-map-search.php on line 49
Deprecated: Creation of dynamic property PH_Map_Search::$label is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-map-search/propertyhive-map-search.php on line 50
Deprecated: Creation of dynamic property PH_Property_Import::$id is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-property-import/propertyhive-property-import.php on line 49
Deprecated: Creation of dynamic property PH_Property_Import::$label is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-property-import/propertyhive-property-import.php on line 50
Deprecated: Creation of dynamic property PH_Propertysalesonlineexport::$id is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-property-sales-online-export/propertyhive-property-sales-online-export.php on line 49
Deprecated: Creation of dynamic property PH_Propertysalesonlineexport::$label is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-property-sales-online-export/propertyhive-property-sales-online-export.php on line 50
Deprecated: Creation of dynamic property PH_Radial_Search::$id is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-radial-search/propertyhive-radial-search.php on line 52
Deprecated: Creation of dynamic property PH_Radial_Search::$label is deprecated in /home/fredestateagents/public_html/wp-content/plugins/propertyhive-radial-search/propertyhive-radial-search.php on line 53
/* ===================================================================== */
/* ==== CREATE NEW PERMALINKS USING /html/s ============================ */
/* ===================================================================== */
function seo_array_text($keyphrase)
{
$phrases = array('Flats & Houses For '.$keyphrase.' in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).' - Find properties with '.get_bloginfo().'',
'Homes For '.$keyphrase.' in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).' - Search properties with '.get_bloginfo().'',
'Property For '.$keyphrase.' in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).' - Start your search for properties with '.get_bloginfo().'',
'Houses For '.$keyphrase.' in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).' - Search properties with '.get_bloginfo().'',
'Unlock your dream home with '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).'. Explore a diverse portfolio of properties and let our expert team guide you through the process.',
'Property for '.$keyphrase.' in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).' Your ideal property awaits you.'
);
return $phrases[array_rand($phrases)];
}
function seo_array_text_no_results($keyphrase)
{
$phrases = array('Selling your home in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).'? We can help. Get a free valuation from a trusted Scottish agent today.',
'Looking for a Free Valuation in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).'? We can help. Get a free market appraisal from a trusted Scottish agent today.',
'Looking for a Property Valuation in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).'? We can help. Get a free market valuation from a trusted Scottish Estate agent today.',
'Market Appraisal for your property in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).'? We can help. Get a free property valuation from a professional Scottish Estate Agent today.',
'Value my property in '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).'? We can help. Get a free property valuation from a professional Scottish Estate Agent today.');
return $phrases[array_rand($phrases)];
}
/* ===================================================================== */
/* ==== CREATE NEW PERMALINKS USING /html/s ============================ */
/* ===================================================================== */
add_action( 'init', function() {
add_rewrite_rule( 'html/s/([^/]*)/([^/]*)/([^/]*)/?$', 'index.php?keyphrase=$matches[1]&county=$matches[2]&town=$matches[3]', 'top' );
add_rewrite_rule( 'html/s/([^/]*)/([^/]*)/?$', 'index.php?keyphrase=$matches[1]&county=$matches[2]', 'top' );
add_rewrite_rule( 'html/s/([^/]*)/?$', 'index.php?keyphrase=$matches[1]', 'top' );
add_rewrite_rule( 'html/([^/]*)/?$', 'index.php?seo=$matches[1]', 'top' );
} );
add_filter( 'query_vars', function( $query_vars ) {
$query_vars[] = 'town';
$query_vars[] = 'county';
$query_vars[] = 'keyphrase';
$query_vars[] = 'seo';
return $query_vars;
} );
add_filter( 'template_include', function( $template )
{
if ( get_query_var( 'town' ) !== '' )
{
require_once( get_stylesheet_directory() . '/seo.php');
}
elseif ( get_query_var( 'county' ) !== '' )
{
require_once( get_stylesheet_directory() . '/seo.php');
}
elseif ( get_query_var( 'keyphrase' ) !== '' )
{
require_once( get_stylesheet_directory() . '/seo.php');
}
elseif ( get_query_var( 'seo' ) == 's' )
{
require_once( get_stylesheet_directory() . '/seo.php');
}
else
{
return $template;
}
} );
/* ===================================================================== */
/* ======================= SEARCH BY RADIUS ============================ */
/* ===================================================================== */
function towns_radial_search_pre_get_posts( $q )
{
add_filter( 'posts_join', 'towns_radial_search_location_posts_join', 10, 2 );
add_filter( 'posts_where', 'towns_radial_search_location_posts_where', 10, 2 );
if ( !isset($_GET['order_by']) || ( isset($_GET['order_by']) && empty($_GET['order_by']) ) )
{
add_filter( 'posts_fields', 'towns_select_field_radius', 10, 2 );
add_filter( 'posts_orderby', 'towns_orderby_radius', 10, 2 );
}
}
function towns_radial_search_location_posts_join( $join, $query )
{
global $wpdb;
if ( isset($_GET['radius']) && !empty($_GET['radius']) && isset($_GET['lat']) && !empty($_GET['lat']) && isset($_GET['lng']) && !empty($_GET['lng']) )
{
$join .= " INNER JOIN $wpdb->postmeta AS mtcustom ON ( $wpdb->posts.ID = mtcustom.post_id ) ";
}
return $join;
}
function towns_radial_search_location_posts_where( $where, $query )
{
global $wpdb;
if ( isset($_GET['radius']) && !empty($_GET['radius']) && isset($_GET['lat']) && !empty($_GET['lat']) && isset($_GET['lng']) && !empty($_GET['lng']) )
{
$lat = sanitize_text_field($_GET['lat']);
$lng = sanitize_text_field($_GET['lng']);
$where .= " AND ";
$where .= " (
$wpdb->posts.ID IN (
SELECT post_id FROM " . $wpdb->prefix . "ph_radial_search_lat_lng_post WHERE
( 3959 * acos( cos( radians(" . trim($lat) . ") )
* cos( radians( lat ) )
* cos( radians( lng )
- radians(" . trim($lng) . ") )
+ sin( radians(" . trim($lat) . ") )
* sin( radians( lat ) ) ) ) <= " . (int)$_GET['radius'] . "
)
) ";
}
return $where;
}
// $args - array( $fields, $query );
function towns_select_field_radius( $fields, $query )
{
if ( isset($_GET['radius']) && !empty($_GET['radius']) && isset($_GET['lat']) && !empty($_GET['lat']) && isset($_GET['lng']) && !empty($_GET['lng']) )
{
global $wpdb;
$lat = $_GET['lat'];
$lng = $_GET['lng'];
$fields .= ",(SELECT ( 3959 * acos( cos( radians(" . trim($lat) . ") )
* cos( radians( lat ) )
* cos( radians( lng )
- radians(" . trim($lng) . ") )
+ sin( radians(" . trim($lat) . ") )
* sin( radians( lat ) ) ) )
FROM " . $wpdb->prefix . "ph_radial_search_lat_lng_post
WHERE
" . $wpdb->prefix . "ph_radial_search_lat_lng_post.post_id = " . $wpdb->prefix . "posts.ID
) AS radius";
unset($_GET['lat']);
unset($_GET['lng']);
}
return $fields;
}
// $args - array( $orderby, $query );
function towns_orderby_radius( $orderby, $query )
{
if ( isset($_GET['radius']) && !empty($_GET['radius']) && isset($_GET['lat']) && !empty($_GET['lat']) && isset($_GET['lng']) && !empty($_GET['lng']) )
{
$orderby = 'radius ASC' . ( ( $orderby != '' ) ? ',' : '' ) . $orderby;
}
return $orderby;
}
function search_by_radius( $atts )
{
ob_start();
// global
global $wpdb, $post;
$atts = shortcode_atts( array(
'department' => 'residential-sales',
'posts_per_page' => -1,
'show_solds' => 'yes',
'radius' => 20,
), $atts);
// SET DEFAULT RADIUS
$_GET['radius'] = $atts['radius'];
$_property['radius'] = $atts['radius'];
// SETBREPLACE {}
$replace = array('{', '}');
$with = array('', '');
// GET LAT LONG
$lat = str_replace($replace, $with, get_seo_town_geo(get_query_var( 'county' ), get_query_var( 'town' ), 'latitude'));
$lng = str_replace($replace, $with, get_seo_town_geo(get_query_var( 'county' ), get_query_var( 'town' ), 'longitude'));
$_GET['lat'] = $lat;
$_GET['lng'] = $lng;
// GETTING RADIUS OF POST TYPES LOOP
foreach ($location_result as $property)
{
$loc_id = $property->ID;
$location = $property->post_title;
$distance = intval($property->distance);
$post_ids[] = $property->ID;
}
// SET UP THE QUERY
$meta_query = array(
array(
'key' => '_on_market',
'value' => 'yes',
)
);
$meta_query[] = array(
'key' => '_department',
'value' => $atts['department'],
'compare' => '='
);
$args = array(
'post_type' => 'property',
'post_status' => 'publish',
'post__in' => $post_ids,
'orderby' => 'post__in',
'posts_per_page' => -1,
'meta_query' => $meta_query,
);
add_action( 'pre_get_posts', 'towns_radial_search_pre_get_posts' );
// WORDPRESS QUERY
$properties = new WP_Query($args);
remove_action( 'pre_get_posts', 'towns_radial_search_pre_get_posts' );
$total_posts = $properties->found_posts;
if($atts['department'] == 'residential-sales')
{
$typesofsales = 'sold/under offer';
$keyphrase = 'Sale';
}
elseif($atts['department'] == 'residential-letting')
{
$typesofsales = 'let/let agreed';
$keyphrase = 'Rent';
}
else
{
$keyphrase = 'Sale';
}
if($total_posts > 0)
{
echo '
'.seo_array_text($keyphrase).'
';
echo '
Your search results: ['.get_seo_county(get_query_var( 'county' )).' - '.get_seo_town(get_query_var( 'county' ), get_query_var( 'town' )).'] ';
if($atts['show_solds'] == 'yes')
{
echo 'Showing all available and '.$typesofsales.' offer properties within '.$_GET['radius'].' miles.';
}
else
{
echo 'Only showing currently available properties within '.$_GET['radius'].' miles.';
}
echo '
Warning: Undefined variable $the_query in /home/fredestateagents/public_html/wp-content/themes/rycramweb/functions.php on line 977
Fatal error: Uncaught Error: Call to a member function have_posts() on null in /home/fredestateagents/public_html/wp-content/themes/rycramweb/functions.php:977
Stack trace:
#0 /home/fredestateagents/public_html/wp-settings.php(710): include()
#1 /home/fredestateagents/public_html/wp-config.php(106): require_once('/home/fredestat...')
#2 /home/fredestateagents/public_html/wp-load.php(50): require_once('/home/fredestat...')
#3 /home/fredestateagents/public_html/wp-blog-header.php(13): require_once('/home/fredestat...')
#4 /home/fredestateagents/public_html/index.php(17): require('/home/fredestat...')
#5 {main}
thrown in /home/fredestateagents/public_html/wp-content/themes/rycramweb/functions.php on line 977