Current File : /home/n742ef5/.trash/royalanteam.com_feb/mls/rm_all.php
<?php

    ini_set('memory_limit', '1024M');
    set_time_limit(0);
    ini_set('max_execution_time', 7200);
    ini_set('display_errors', 1);
    ini_set("log_errors", 1);
    error_reporting(E_ALL);
    date_default_timezone_set('America/Toronto');
    //echo "<pre>cxcxc";

        
    $main_directory = '/home/n742ef5/royalanteam.com/';
    require_once("config/mls_config.php");
    require_once("lib/phrets.php");
    require_once("config/properties_config.php");
    require_once("/home/n742ef5/royalanteam.com/wp-load.php");
    global $wpdb;
    //exit;
    $timestamp_field = 'Timestamp_sql'; 
    $file_name       = "sold_property";
    $curr_resource   = "Property";
    $className       = "ResidentialProperty";
    $mls_key_field   = "Ml_num";
    
    $curr_mls_id     = 1;
    $curr_date          = date('Y-m-d H:i:s');
    $cron_tablename     = 'properties_cron_log';
    $tmp_tablename      = 'rets_property_data_resi';

    $sql_query = "SELECT Ml_num FROM `rets_property_data_resi` where property_last_updated < '2024-01-19'";
    $all_post = $wpdb->get_results( $sql_query );
    if ($all_post && !empty($all_post) ) {
        foreach($all_post as $curr_post){
            $qn_query = "SELECT post_id FROM LgJ_postmeta where meta_value ='$curr_post->Ml_num'";
            $pre_post = $wpdb->get_results( $qn_query,ARRAY_A );
            if ($pre_post && !empty($pre_post) ) {
                foreach($pre_post as $each_posts){
                    $post_id  = $each_posts['post_id'];
                    echo "<br>Post Id :".$post_id;
                    //exit;
                    // Add this id in a Temp Table
                  
                  	$media  = get_attached_media('', $post_id);
                    if (isset($media) && count($media) > 0) {
                        foreach ($media as $photo) {
                            //print_r($photo);
                            echo "<br>".$main_image_path = $photo->post_content_filtered;
                            //continue;
                            error_log("Image " . $main_image_path . "<br>");
                            @unlink($main_image_path);
                            $thumbnail_image_src    = wp_get_attachment_image_src($photo->ID, 'thumbnail');
                            $thumbnail_relative_url = str_replace($website_uri.'/', $main_directory, $thumbnail_image_src['0']);
                                        
                            @unlink($thumbnail_relative_url);
                            $image_post_id   = $photo->ID;
                            $wp_delete_query = "DELETE FROM $wpdb->postmeta where post_id=$image_post_id";
                            $wpdb->query($wp_delete_query);
                            $wp_delete_query = "DELETE FROM $wpdb->posts where ID =$image_post_id";
                            $wpdb->query($wp_delete_query);
                        }
                    }
                    //continue;
                    //exit;
                    $wp_delete_query = "DELETE FROM $wpdb->postmeta where post_id=$post_id and meta_key in('_iwp_gallery','fave_property_images')";
                    $wpdb->query($wp_delete_query);
                                            
                    $remove_query_meta = "DELETE FROM $wpdb->postmeta  where post_id = $post_id ";
                    $result_remove     = $wpdb->query($remove_query_meta);
                              
                    $del_term = "DELETE FROM $wpdb->term_relationships where object_id = $post_id ";
                    $wpdb->query($del_term);
                  
                    $remove_main   = "DELETE FROM $wpdb->posts where ID = $post_id ";
                    $result_remove = $wpdb->query($remove_main);
                    
                }
            }
            $remove_main   = "DELETE FROM $tmp_tablename where Ml_num = '$curr_post->Ml_num' ";
            $result_remove = $wpdb->query($remove_main);
        }
    }