Home Forums General Issues Grab ACF field value based on user's company


Grab ACF field value based on user's company

  • Hello-

    I have a custom post type called Company

    I then use ACF to create a Post Object for Company that gets displayed in the Users admin page.

    From there, for any users, I am able to assign a company.

    I am able to grab the Company name using the code below:

    $user_id = get_current_user_id();
    $user_company = get_field('user_company', 'user_' . $user_id);
    echo $user_company->post_title;

    BUT, I need help with grabbing a specific data from the Company post type. When I did a var_dump, it only displays information about the post like id, title, author, etc.

    There is a text field called RTN and that’s what I need to get.

    Basically what I want to do is for current logged in user, grab RTN data from Company post based on post object selected.

    I hope that made sense.

  • I got it!

    I just add this as the 3rd line

    $company_rtn = get_field('rtn', $user_company->ID);

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

You must be logged in to reply to this topic.