rep__get_agency()

This function is used to retrieve the agency post ID associated with a listing or agent based on the provided post ID.

Namespace

REP_Malcolm

Parameters

$post_id

int

Post ID of the agent

Return

string

Agent post ID

Source

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

function rep__get_agency( $post_id ){

    $agency_id = lp__get_field_value('agency_id', $post_id);
    $agency_post_id = "";
    
    $args = array(
        'post_type' => 'rep_agency',
        'posts_per_page' => 1,
        'lp__meta_query' => array(
            array(
                'key' => 'agency_id',
                'value' => $agency_id,
                'compare' => '='
            )
        )
    );

    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 ){
            $agency_post_id = $post->ID;
            break;
        }
    }

    return $agency_post_id;

}