rep__get_listing_agents()

This function is used to retrieve a list of agent post IDs associated with a listing based on the provided post ID.

Namespace

REP_Malcolm

Parameters

$post_id

int

Post ID of the listing.

Return

string

An array containing listing agents

Source

File: \includes\rep-helper-functions.php

function rep__get_listing_agents( $post_id ){

    global $wpdb;

    $listing_agents = (array)maybe_unserialize(lp__get_field_value('listing_agents', $post_id));
    $agent_ids = [];
    $agent_post_ids = [];

    if( is_array( $listing_agents ) && ! empty( $listing_agents ) ){
        foreach( $listing_agents as $agent ){
            $agent_id = lp__array_key_value( "id", $agent, "" );
            $agent_ids[] = $agent_id;
        }

        $args = array(
            'post_type' => 'rep_employee',
            'posts_per_page' => -1,
            'rep__employee_id__in' => $agent_ids,
            'orderby' => 'rep__employee_id__in'
        );

        if( ! is_admin() ){
            $args['post_status'] = 'publish';
            $args['has_password'] = false;
            $args['lp__post_hidden'] = false;
        }

        $query = new WP_Query($args);
        $posts = $query->get_posts();

        foreach( $posts as $post ){
            if( $post instanceof WP_post ){
                $agent_post_ids[] = $post->ID;
            }
        }
    }

    return $agent_post_ids;

}