WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ok, so this sounds a little complex, but in theory should be easy.

What I'm trying to achieve:

ACF data is pulled from a WP page which has the same name as the current logged in user.

Basically I will have a WP page set up for each company. I will create a login for each company with an appropriate username. The name of the company page will be the exact same name as the username I create. It will have Advanced Custom Fields entered with data.

I want to dynamically pull in the ACF data from the company page based on the current user logged in into my page template.

So if company A are logged in, I want them to view the custom fields from company A's page. Company B log in and view the custom fields from the company B page.

So far, I have this:

      global $user_login;
      $username = $current_user->user_login;
      $other_page = $username;
    <p><?php the_field('my_custom_field', $other_page); ?></p>

Which in theory should work, but it just doesn't.

I can check the current username of the logged in user and echo it which returns the correct username just fine on the page.

I can also add a page ID by adding the page ID like this: $other_page = 890; and it pulls in the custom field data from the correct company page (890 being one of the company pages).

So everything works as it should independently, just not when I want to use the logged in username as the name of the page (namely $other_page).

I'm baffled with this so any help would be greatly appreciated.

share|improve this question

According with docs, when you want to retrieve field attached to post using get_field / the_field you should pass a numeric ID as 2nd argument.

You are passing a string.

So your code should work if:

$login = wp_get_current_user()->user_login;
$page = $login ? get_page_by_path( $login ) : false;
$field = $page ? get_field('my_custom_field', $page->ID) : false;
share|improve this answer
Hi there, thanks for your help with this. – Phil Owen Sep 24 '13 at 21:55
Hi @PhilOwen, it worked for you? – gmazzap Sep 24 '13 at 22:32
No. I couldn't get it working with this. – Phil Owen Sep 25 '13 at 19:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.