• Resolved bchristopher

    (@bchristopher)


    Hello,

    I’m needing to get the Adverts Author ID on the list-item.php template. I tried using the following:
    get_post_field( 'post_author', $post_id )

    However, this returns the WordPress user ID, not the adverts author ID. I need this so I can access meta data on the author post object.

    If I can’t get the author ID, is there a way I can get meta values from the author post type?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    the Author profile is basically a Custom Post Type “advert-author” assigned to a user, so in order to ger the Author ID you can use the code below

    
    $user_id = get_post_field( 'post_author', $post_id );
    $args = array(
        'author'         => $user_id,
        'post_type'      => 'advert-author',
        'posts_per_page' => 1,
        'post_status'    => array( 'publish', 'advert-hidden' ),
    );
    $author_page = get_posts( $args );
    $author_id = null;
    if( isset( $author_page[0] ) ) {
      $author_id = $author_page[0]->ID;
    }
    
    Thread Starter bchristopher

    (@bchristopher)

    Perfect, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Get Adverts Author ID’ is closed to new replies.