Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Resetting a has_members query

  • Hey BP community,

    I built myself a handy little “Who’s Online” widget that displays the number of current active members and displays up to 10 names of current browsers in my footer.

    The only issue I have with it is on any page that already uses a bp_has_members() loop, the arguments of the main loop override my Who’s Online listing, causing it to repeat the same list of users.

    I know with a WordPress posts loop I can use wp_reset_query() to destroy any existing queries to use multiple loops on a page. Is there a buddypress equivalent function for has_members()?

    Thanks!
    Andrew

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

  • danbpfr
    Participant

    @chouf1

    Hi,

    sorry to ask that, but why don’t you use the built in BP widget Who’s online ?
    for inspiration, see how it is built in bp-core-widget.php:124
    You can also use bp-skeleton to built your own widget on a proper maner.
    https://wordpress.org/extend/plugins/buddypress-skeleton-component/

    I had built some functionality into my widget which the stock BP who’s online didn’t incorporate. My code is actually pretty similar to the stock widgets in bp-core-widget, but yet I run into this issue where any other has_members query contaminates the contents of my widget. There must be some trick that I’m missing to initiate a has_members query that resets any pre-existing query…


    Yukon Cornelius
    Participant

    @jimmmy

    @aaclayton any luck figuring this out?


    aaclayton
    Member

    @aaclayton

    Hey @jimmmy, I had forgotten about this issue. My new theme design only uses the has_members query once per page, as I had moved the “who’s online widget” on my site to a sidebar that is not displayed on other directories with members loops.

    I’m not certain if this is still an issue or not, but one thing I suppose you could try is saving the contents of $members_template to a temporary placeholder variable before issuing your custom has_members query. Once you’ve run the loop on your secondary query you could restore the original contents of $members_template.


    Yukon Cornelius
    Participant

    @jimmmy

    @aaclayton Thanks for responding! I will give that a go, but i think it’s beyond my skill level. I was hoping i could pop in something like bp_reset and everything would be cool…

    Cheers.


    Yukon Cornelius
    Participant

    @jimmmy

    In case anyone is having the same problem, the solution i came up with was to make a plugin using the buddypress members widget core code, as @danbpfr suggested. That widget was not breaking things, so once i had a plugin version i was able to add some of the extra things that were in my original loop.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Resetting a has_members query’ is closed to new replies.
Skip to toolbar