Home Forums General Issues Grab relationship field from user profile


Grab relationship field from user profile

  • I am confused on how to grab the relationship field from user profile.

    I have a custom post type called Companies with a field called longname. A relationship field added to user profile called user_company.

    I am trying to get the company of logged in user.

    All I have is

    $user_id = get_current_user_id();
    $company = get_field('user_company', 'user_' . $user_id->ID);
    echo $company;
    $company = get_field('user_company', 'user_' . $user_id);
  • After doing a var_dump on $company, the reason why echoing $compmany wasn’t pulling anythng was because it was a wp object or wp array (I’m not sure of the correct terminology.

    I had to select the post_title in order for it to work. So I ended up with this:

    function user_organization($atts) {
    	$user_id = get_current_user_id();
    	$user_company = get_field('user_company', 'user_' . $user_id);
    	echo $user_company->post_title;
    add_shortcode('user_organization_info', 'user_organization');
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.