posts WHERE post_type = '$post_type' AND post_status = 'publish'"; $num_records = $wpdb->get_var($sql); $sql1 = "SELECT ID FROM $wpdb->posts WHERE RAND()*$num_records<20 ORDER BY RAND() LIMIT 0,80"; $query = $wpdb->get_results($sql1); $id_in = array(); foreach ($query as $q) { $id_in[] = "$q->ID"; } $expired_listing = array(); $expired_listing = get_option('gc_expired_listing'); $id_in = implode(',', $id_in); $sql2 = "SELECT * FROM $wpdb->posts WHERE ID IN($id_in)"; $listing_result = $wpdb->get_results($sql2); if (!empty($listing_result)) { foreach ($listing_result as $listing) { //echo 'ID: ' . $listing->ID . '
'; debug $is_expiry_set = get_post_meta($listing->ID, 'gc_listing_duration', true); /** * Check if listing expiry date is already set. * If not set, it will set the expiry date based on current free package active period. */ if (!$is_expiry_set) { gc_set_expiry($listing->ID); } $message = ''; if (!empty($expired_listing) && is_array($expired_listing)) { $is_expired = in_array($listing->ID, $expired_listing); } //getting listing status $expire = gc_has_ad_expired($listing->ID); //if listing expired if ($expire == true && empty($is_expired)) { $post_author = $listing->post_author; $site_name = get_option('blogname'); $email = get_option('admin_email'); $website_link = get_option('siteurl'); $listing_title = $listing->post_title; $lisgint_guid = $listing->guid; $login_url = site_url("/wp-login.php?action=login"); $listing_user_name = get_the_author_meta('user_login', $post_author); $message .= "--------------------------------------------------------------------------------\r"; $message .= "Dear $listing_user_name, \r"; $message .= "Your listing is expired. We inform you that, if you are interested to reactivate your listing, \r"; $message .= "Login in our website and reactivate it. \r"; $message .= "--------------------------------------------------------------------------------\r"; $message .= "Listing Title: $listing_title \r"; $message .= "Login On: $login_url \r"; $message .= "--------------------------------------------------------------------------------\r"; $message .= "Website: $site_name\r"; $message .= "Website URL: $website_link\r"; $message .= "--------------------------------------------------------------------------------\r"; $message = __($message, THEME_SLUG); //get listing author email $to = get_the_author_meta('user_email', $post_author); $subject = 'Your listing reactivation notice'; $headers = 'From: Site Admin <' . $email . '>' . "\r\n" . 'Reply-To: ' . $email; if (empty($expired_listing)) { $array = array(); update_option('gc_expired_listing', $array); } $expired_listing = (array) get_option('gc_expired_listing'); array_push($expired_listing, $listing->ID); update_option('gc_expired_listing', $expired_listing); wp_mail($to, $subject, $message, $headers); } } }