rep__get_agency_post_id()
This function, retrieves a post ID based on either an agency ID or agency location id from the database and returns it as data.
Namespace
REP_Malcolm
Return
data
Agency post ID data
Source
File: \includes\rep-helper-functions.php
function rep__get_agency_post_id( $id, $type='agency_id' ){
global $wpdb;
$post_id = null;
$args = array(
'post_type' => 'rep_agency',
'posts_per_page' => 1,
'lp__meta_query' => array(
array(
'key' => $type,
'value' => $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 ){
$post_id = $post->ID;
}
}
return $post_id;
}