| Server IP : 35.235.84.95 / Your IP : 216.73.216.49 Web Server : Apache System : Linux instance-1 6.1.0-33-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.133-1 (2025-04-10) x86_64 User : vanessavaladezrealty ( 10093) PHP Version : 8.0.30 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/vanessavaladezrealty.com/httpdocs/wp-content/themes/astra-child/ |
Upload File : |
<?php
/**
* Astra Child Theme functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Astra Child
* @since 1.0.0
*/
require_once('vendor/RESO-WebAPI-Client-PHP-master/init.php');
/**
* Define Constants
*/
define( 'CHILD_THEME_ASTRA_CHILD_VERSION', '1.0.0' );
/**
* Enqueue styles
*/
global $wpdb;
function child_enqueue_styles() {
wp_enqueue_style( 'astra-child-theme-css', get_stylesheet_directory_uri() . '/style.css', array('astra-theme-css'), CHILD_THEME_ASTRA_CHILD_VERSION, 'all' );
}
add_action( 'wp_enqueue_scripts', 'child_enqueue_styles', 15 );
// Adds properties from Trestle IDX+ API to database
function update_mls_database() {
global $wpdb;
$fmt = numfmt_create( 'en_US', NumberFormatter::CURRENCY );
RESO\RESO::setClientId('trestle_VertexVisibilityWebsiteDesign20211229121314'); // set to your client id
RESO\RESO::setClientSecret('3634faa60ef740de839a606c2d59be26'); // set to your client secret
RESO\RESO::setAPITokenUrl('https://api-prod.corelogic.com/trestle/oidc/connect/token');
RESO\RESO::setAPIRequestUrl('https://api-prod.corelogic.com/trestle/odata/');
// Get access token
RESO\RESO::setAccessToken(RESO\OpenIDConnect::requestAccessToken(null, 'https://api-prod.corelogic.com/trestle/odata/', 'api'));
$data = RESO\Request::request('Property?$top=50&$expand=Media', 'json', true);
$properties = $data['value'];
foreach ($properties as $prop) {
$property_id = $wpdb->get_var('SELECT id FROM YTPb5_wpl_properties WHERE mls_id_num = "'.$prop['ListingKeyNumeric'].'"');
$property_type = 1;
switch ($prop['PropertyType']) {
case 'BusinessOpportunity':
$property_type = 21;
break;
case 'CommercialLease':
$property_type = 20;
break;
case 'CommercialSale':
$property_type = 19;
break;
case 'Farm':
$property_type = 18;
break;
case 'Land':
$property_type = 14;
break;
case 'ManufacturedInPark':
$property_type = 17;
break;
case 'Residential':
$property_type = 1;
break;
case 'ResidentialIncome ':
$property_type = 16;
break;
case 'ResidentialLease':
$property_type = 15;
break;
default:
$property_type = 1;
}
$property_type_text = $wpdb->get_var("SELECT name FROM YTPb5_wpl_property_types WHERE id = $property_type");
$lot_size_unit = 3;
switch ($prop['LotSizeUnits']) {
case 'Acres':
$lot_size_unit = 3;
break;
case 'SquareFeet':
$lot_size_unit = 1;
break;
case 'SquareMeters':
$lot_size_unit = 2;
break;
}
$living_area_unit = 1;
switch ($prop['LivingAreaUnits']) {
case 'SquareFeet':
$living_area_unit = 1;
break;
case 'SquareMeters':
$living_area_unit = 2;
break;
}
// Add property to DB table
$wpdb->replace(
'YTPb5_wpl_properties',
array(
'id' => $property_id,
'kind' => '',
'deleted' => '',
'mls_id' => $prop['ListingKey'],
'mls_id_num' => $prop['ListingKeyNumeric'],
'parent' => '',
'pic_numb' => '',
'user_id' => 3,
'listing' => '',
'property_type' => $property_type,
'location1_id' => 0,
'location2_id' => 6034,
'location3_id' => '',
'location4_id' => '',
'location5_id' => '',
'location6_id' => '',
'location7_id' => '',
'location1_name' => 'USA',
'location2_name' => $prop['StateOrProvince'],
'location3_name' => NULL,
'location4_name' => $prop['City'],
'location5_name' => NULL,
'location6_name' => NULL,
'location7_name' => NULL,
'show_address' => 1,
'price' => $prop['ListPrice'],
'price_unit' => 260,
'price_si' => $prop['ListPrice'],
'price_period' => 0,
'bedrooms' => $prop['BedroomsTotal'] ?: 0,
'rooms' => $prop['RoomsTotal'] ?: 0,
'bathrooms' => $prop['BathroomsTotalInteger'] ?: 0,
'living_area' => $prop['LivingArea'] ?: 0,
'living_area_unit' => $living_area_unit,
'living_area_si' => 0,
'lot_area' => $prop['LotSizeArea'] ?: 0,
'lot_area_unit' => $lot_size_unit,
'lot_area_si' => 0,
'googlemap_lt' => $prop['Latitude'],
'googlemap_ln' => $prop['Longitude'],
'finalized' => 1,
//'add_date' => '',
//'last_finalize_date' => '',
'expire_days' => 0,
'confirmed' => 1,
'expired' => 0,
'build_year' => $prop['YearBuilt'] ?: 0,
'zip_id' => 0,
'zip_name' => $prop['PostalCode'],
//'last_modified_time_stamp' => '',
'post_code' => null,
'meta_description' => '',
'meta_description_manual' => '',
'meta_keywords' => '',
'meta_keywords_manual' => 0,
'street_no' => $prop['StreetNumberNumeric'],
'sp_featured' => 0,
'sp_hot' => 0,
'sp_openhouse' => 0,
'sp_forclosure' => 0,
'textsearch' => $prop['PublicRemarks'],
'location_text' => $prop['UnparsedAddress'],
'field_42' => $prop['StreetName'],
'field_312' => $property_type_text.' - '.numfmt_format_currency($fmt, $prop['ListPrice'], "USD"), // Property Page Title
'field_313' => $prop['UnparsedAddress'].' - '.$property_type_text, // Property Title
'field_308' => $prop['PublicRemarks'], // Property desc
'field_7' => '',
'ref_id' => '',
'field_54' => '',
'half_bathrooms' => $prop['BathroomsHalf'] ?: 0,
'field_55' => '',
'rendered' => '',
'alias' => '',
'source' => 'trestle',
'last_sync_date' => '',
'street_suffix' => $prop['StreetSuffix'],
)
);
$property_id = $wpdb->insert_id;
// Add info to DB properties2 table
$is_in_properties2 = $wpdb->get_var("SELECT id FROM YTPb5_wpl_properties2 WHERE id = $property_id");
if (is_null($is_in_properties2)) {
$wpdb->insert(
'YTPb5_wpl_properties2',
array(
'id' => $property_id,
'att_numb' => 0,
'sent_numb' => 0,
'contact_numb' => 0,
'inc_in_listings_numb' => 0,
'visit_time' => 0,
'visit_date' => NULL,
'vids_numb' => 0
)
);
}
// Add images to DB table
foreach($prop['Media'] as $media) {
$media_id = $wpdb->get_var('SELECT id FROM YTPb5_wpl_items WHERE item_name = "'.$media['MediaKey'].'"');
$wpdb->replace(
'YTPb5_wpl_items',
array(
'id' => $media_id,
'parent_kind' => 0,
'parent_id' => $property_id,
'item_type' => 'gallery',
'item_cat' => 'external',
'item_name' => $media['MediaKey'],
//'creation_date => '',
//'edit_date' => '',
'enabled' => 1,
'item_extra1' => NULL,
'item_extra2' => NULL,
'item_extra3' => $media['MediaURL'],
'item_extra4' => NULL,
'item_extra5' => NULL,
'params' => NULL,
'index' => 99.0,
)
);
}
}
}
add_action('update_mls_database', 'update_mls_database');
// Shortcode to output custom PHP in Elementor
function mls_listing_show($atts) {
ob_start();
$atts = shortcode_atts(array('rows' => 2), $atts, 'home_mls_list');
global $wpdb;
$fmt = numfmt_create( 'en_US', NumberFormatter::CURRENCY );
$query = "SELECT properties.*, property_type.name as property_text, units.name as unit_text FROM YTPb5_wpl_properties as properties LEFT JOIN YTPb5_wpl_property_types as property_type ON properties.property_type=property_type.id LEFT JOIN YTPb5_wpl_units as units ON properties.lot_area_unit=units.id WHERE properties.source = 'trestle'";
$properties = $wpdb->get_results($query);
echo '<section class="elementor-section elementor-inner-section elementor-element elementor-element-c554e50 elementor-section-content-top elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="c554e50" data-element_type="section"><div class="elementor-container elementor-column-gap-no">';
foreach ($properties as $key=>$prop) {
$property_icon_class = "fa fa-home";
if ($prop->{'property_type'} == 2 || $prop->{'property_type'} == 13 || $prop->{'property_type'} == 17 || $prop->{'property_type'} == 19 || $prop->{'property_type'} == 20 || $prop->{'property_type'} == 21) {
$property_icon_class = "fas fa-building";
}
if ($key % 3 == 0) {
if ($key >= $atts['rows']*3) {
echo '</div><div class="listing-row elementor-container elementor-column-gap-no hide" style="transition: height: 2s, opacity: 2s ease;">';
}
else {
echo '</div><div class="listing-row elementor-container elementor-column-gap-no">';
}
}
$img_url = $wpdb->get_var('SELECT item_extra3 FROM YTPb5_wpl_items WHERE parent_id = "'.$prop->{'id'}.'"');
$prop_link = add_query_arg(array(
'wplview' => 'property_show',
'pid' => $prop->{'id'},
), get_permalink(16));
$col = '<div class="elementor-column elementor-col-33 elementor-inner-column elementor-element elementor-element-72eb57e" data-id="72eb57e" data-element_type="column">
<div class="elementor-widget-wrap elementor-element-populated" style="padding: 0px 1px 25px 1px;">
<div class="elementor-element elementor-element-95de904 elementor-widget elementor-widget-image" data-id="95de904" data-element_type="widget" data-widget_type="image.default">
<div class="elementor-widget-container">
<a href="'.$prop_link.'">
<img width="390" height="260" src="'.$img_url.'" alt="" loading="lazy" style="width: 390px; height: 260px; aspect-ratio: 390/260">
</a>
</div>
</div>
<div class="elementor-element elementor-element-252549e elementor-align-left elementor-icon-list--layout-traditional elementor-list-item-link-full_width elementor-widget elementor-widget-icon-list" data-id="252549e" data-element_type="widget" data-widget_type="icon-list.default">
<div class="elementor-widget-container">
<ul class="elementor-icon-list-items">
<li class="elementor-icon-list-item">
<span class="elementor-icon-list-icon">
<i aria-hidden="true" class="fas '.$property_icon_class.'">
</i>
</span>
<span class="elementor-icon-list-text">'.$prop->{'property_text'}.'
</span>
</li>
</ul>
</div>
</div>
<div class="elementor-element elementor-element-133a31a elementor-widget elementor-widget-heading" data-id="133a31a" data-element_type="widget" data-widget_type="heading.default">
<div class="elementor-widget-container">
<h5 class="elementor-heading-title elementor-size-default">'.numfmt_format_currency($fmt, $prop->{'price'}, "USD").'
</h5>
</div>
</div>
<div class="elementor-element elementor-element-aa8e04f elementor-widget elementor-widget-heading" data-id="aa8e04f" data-element_type="widget" data-widget_type="heading.default">
<div class="elementor-widget-container">
<h6 class="elementor-heading-title elementor-size-default">'.$prop->{'location_text'}.'
</h6>
</div>
</div>
<div class="elementor-element elementor-element-ac5539f elementor-widget elementor-widget-text-editor" data-id="ac5539f" data-element_type="widget" data-widget_type="text-editor.default">
<div class="elementor-widget-container">
<p>Rooms: '.$prop->{'bedrooms'}.' / Baths: '.$prop->{'bathrooms'}.' / Lot Size: '.$prop->{'lot_area'}.' '.$prop->{'unit_text'}.'
</p>
</div>
</div>
<!--<div class="elementor-element elementor-element-47ac6ca elementor-widget elementor-widget-button" data-id="47ac6ca" data-element_type="widget" data-widget_type="button.default">
<div class="elementor-widget-container">
<div class="elementor-button-wrapper">
<a href="#" class="elementor-button-link elementor-button elementor-size-sm" role="button">
<span class="elementor-button-content-wrapper">
<span class="elementor-button-text">Details
</span>
</span>
</a>
</div>
</div>
</div>-->
</div>
</div>';
echo $col;
}
echo '</div>
</section>';
return ob_get_clean();
}
add_shortcode( 'home_mls_list', 'mls_listing_show');