Skip to:
Content
Pages
Categories
Search
Top
Bottom

Cant get bp_has_members() parameters working when using a variable

  • @darrenmeehan

    Participant

    I’m trying to showcase 6 random members on my homepage, while showing all members in the members directory.

    I’m using this code to change the number when its on the homepage. Which seems to be working fine.
    `if(is_front_page())
    {
    $dm_number = 6;
    }
    else
    {
    $dm_number = 20;
    }`

    but when I use the variable in bp_has_members() is doesnt work, it does work if I replace the variable with 6 though. The random parameter isnt working either.

    `if ( bp_has_members(“include=$filtered_users&max=$dm_number&type=random”) ) : ?>`

    I’m using the latest BP & WP, running on localhost – lamp environment. I’m also using this plugin for sorting out user types – http://wordpress.org/extend/plugins/buddypress-user-account-type-lite/ this is why `include=$filtered_user` is being used.

    I’m still getting my head around PHP and its been a while since I’ve used BuddyPress, I think my syntax is ok but I cant be sure! Any help would be appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • @shanebp

    Moderator

    Your syntax is wrong. Variables can’t be in quotes. You have to build your parameter string.
    Sometimes it’s less confusing to build it ‘outside’

    `
    $the_members_you_want = “include=” . $filtered_users . “&max=” . $dm_number . “&type=random”;
    if ( bp_has_members( $the_members_you_want ) )
    `

    @darrenmeehan

    Participant

    Oops thanks for that Shane! I’ll read over some more PHP again. I think I’ve made the required changes, but its still not working. I’ve posted the whole file to here https://gist.github.com/2882028. I’d love if I could figure out where I’m wrong.

    @shanebp

    Moderator

    “not working” is too general a comment.

    What parts are working?

    You need to methodically narrow down to the problem areas.
    echo out your $vars to see if it’s what you expect.
    For example:

    `
    $filtered_users=buat_gather_user_ids($type);
    echo “
    filtered_users: ” . $filtered_users . “
    “;

    $the_members_you_want = “include=” . $filtered_users . “&max=” . $dm_number . “&type=random”;
    echo “
    members-you-want: ” . $the_members_you_want . “
    “;

    `

    And how does $dm_number get from buat_shortcode_grabber() to buat_get_user_template()?

    You probably want to generate it in buat_get_user_template() instead of buat_shortcode_grabber()

    etc.

    @darrenmeehan

    Participant

    Thanks for your help Shane, I wasn’t thinking properly as a programmer – I spent more time trying to figure out what I didn’t know, and less time using what I did. My variable wasn’t global, though reading into PHP having this is a bad idea. So I moved
    `if(is_front_page())
    {
    $dm_number = 6;
    }
    else
    {
    $dm_number = 20;
    }`

    into the same function as where the variable is being used. The random parameter doesn’t seem to be doing anything, I’m going to try and narrow this problem down today. Thanks again for your help! You’ve me thinking the right way now :D

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Cant get bp_has_members() parameters working when using a variable’ is closed to new replies.
Skip to toolbar