Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get user ID (and custom field) outside of loop


  • RobFenech
    Participant

    @terydinho

    Hi all, I am really struggling today for some reason. What I want to do is this.

    I have a CPT that is working perfectly with a custom taxonomy of County, users post up posts/events in a certain county. When a user signs up, they choose a County too. So the aim is to show all posts from within said users County.

    I was going to do it like this:

    `$args=array(
    ‘taxonomy’ => ‘counties’,
    ‘counties’ => ‘Essex’,
    ‘post_type’ => ‘matches’,
    ‘posts_per_page’ => 3
    );

    query_posts( $args ); ?>`

    But how do I grab the user county? I tried using bp_member_profile_data – but that seems to get the latest user rather than who is logged in… any ideas?

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

  • Boone Gorges
    Keymaster

    @boonebgorges

    The function you want is `xprofile_get_field_data()`. It takes two parameters: the field name/ID, and the user_id. So, for the logged in user,

    `$county = xprofile_get_field_data( ‘County’, bp_loggedin_user_id() );`


    RobFenech
    Participant

    @terydinho

    Boone, thank you so much! I have been tearing my hair out on this!!

    Thanks mate

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get user ID (and custom field) outside of loop’ is closed to new replies.
Skip to toolbar