MP_Addon_Calls_Callback::request_lead( string $phone )

Request Lead by phone number in database.


Parameters Parameters

$phone

(string) (Required) phone number.


Top ↑

Return Return

(mixed)


Top ↑

Source Source

File: calculator-calls-add-on/inc/MP_Addon_Calls_Callback.php

	protected function request_lead( $phone ) {

		$found = false;
		$phone_query = wp_cache_get('calls_addon_posts',MortgagePlatform::$domain, false, $found);
		if(!$found){
			$phone_query = new \WP_Query(
				array(
					'post_type'      => array( MortgagePlatform::$lead, MortgagePlatform::$abandoned_lead ),
					'posts_per_page' => - 1,
					'post_status'    => array( 'publish', 'pending' ),
					'orderby'        => array(
						'ID' => 'DESC',
					),
					'meta_query'     => array(
						'relation' => 'OR',
						array(
							'key'   => MortgagePlatform::$prefix . 'lead_phone',
							'value' => $phone,
						),
						array(
							'key'   => MortgagePlatform::$prefix . 'abandoned_lead_phone',
							'value' => ltrim( $phone, '+' ),
						),
					),
				)
			);
			wp_cache_set('calls_addon_posts', $phone_query, MortgagePlatform::$domain, WEEK_IN_SECONDS);
		}


		if ( $phone_query->have_posts() ) {

			$leads = array();

			while ( $phone_query->have_posts() ) {
				$phone_query->the_post();

				$post_id = $phone_query->post->ID;
				array_push( $leads, $post_id );

			}

		}

		wp_reset_postdata();

		return $leads[0];

	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.