Support » Plugin: BP Profile Search » Results Page retrieve displayed members’ IDs

  • Hi there,

    First and foremost, thank you for the work on this plugin. It’s such a leap forward for any BP setup and is literally a must for community search.

    I’m hoping you can help me. I’m looking for a way to retrieve a list of displayed User IDs once a search has been made. So visitor filters members page by member type field for example and is shown a list of all members of that member type. Is there a way to retrieve the user IDs of those members displayed? ideally some sort of loop?

    Any help would be huge. Thank you!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Andrea Tarantini

    (@dontdream)

    Hi y2gabs,

    Why do you need the user IDs of the search results? I’m asking because probably there is a simpler way to achieve what you need.

    Thank you sir for your reply here! I’m using a messaging plugin (as an alternative to the buddypress msg functionality) that opens a new message window and includes the recipients in the “To” field who’s user IDs are included in the new message url. So it would look like this:
    http://mydomain.com/blahblah/new message&uid=1,5,6,etc

    Clicking that link would open a new message for the users with those IDs. So usecase is someone filters for desired users, results page includes a dynamic link generated by displayed users link described above, and a message box pops up with those filtered users in the To field.

    Make sense?

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi y2gabs,

    Thank you for your explanation!

    You could use the filter ‘bps_search_results’ to save the user IDs for later use:

    add_filter ('bps_search_results', 'save_user_ids');
    function save_user_ids ($user_ids)
    {
    	global $saved_user_ids;
    
    	$saved_user_ids = $user_ids;
    	return $user_ids;
    }

    Thank you so much sir for your help here. Sorry for my delay, I had to wait to the weekend to implement. Could you help me understand a little bit. How can I get the above code to output a string of displayed user ids with commas between each? Trying to use this function with a shortcode call in my functions.php doesn’t seem to be displaying anything.

    Thank you so much!

    Plugin Author Andrea Tarantini

    (@dontdream)

    Hello y2gabs,

    I assume you are able to display your dynamic link with a fixed list of numbers in your results page.

    Now, add the code I provided to your bp-custom.php file (functions.php is OK too). Then go back to the code you use to display your dynamic link, and replace the fixed list of numbers with those in the global $saved_user_ids array.

    Hope this helps!

    Hi Andrea! Thank you so much for your help here and I sincerely apologize for my tardy response. I only have the time to try this code on the weekends due to fulltime weekday job but am now on holidays and can dedicate more to this project. So I tried the code again last weekend by adding it to functions.php as follows. And tried calling it via shortcode in to my URL. I am indeed able to get the URL to work no problem with static user IDs (comma separated as discussed) but the following code does not seem to return anything. Any help you can provide would be greatly appreciated. Thank you so much again!

    add_filter ('bps_search_results', 'save_user_ids');
    function save_user_ids ($user_ids)
    {
    	global $saved_user_ids;
    
    	$saved_user_ids = $user_ids;
    	return $user_ids;
    }
    
    add_shortcode( 'displayed_user_ids', 'save_user_ids' );
    • This reply was modified 6 months, 2 weeks ago by y2gabs.
    Plugin Author Andrea Tarantini

    (@dontdream)

    Hi y2gabs,

    Try this:

    1) enter the code I provided as it is, without adding the add_shortcode line, in your bp-custom.php file (functions.php is OK too);

    2) now go back to your URL with comma separated user IDs, and replace the user ID list with the saved IDs, like this:

    // replace
    
    http://your_url/?ids=2,3,4,5
    
    // with
    
    http://your_url/?ids=<?php global $saved_user_ids; echo implode (',', $saved_user_ids); ?>

    Thank you so much Andrea. One problem is that I’m trying to add the Message URL via widget (long story) and without using some additional code enabled widget. So my only option is to do so with a shortcode. Is there an adjustment to the code provided above that would let me insert the URL as a shortcode or at least the dynamic portion as a shortcode?

    Thanks again!

    Plugin Author Andrea Tarantini

    (@dontdream)

    I suggest you add your static URL with a shortcode in the way you need for your project. That’s independent of BP Profile Search, so you don’t need my support there.

    Then go back to the static URL you already added with your shortcode, replace the static ID list with the code I explained above, and that should do the trick.

    y2gabs

    (@y2gabs)

    Thanks Andrea. The problem is that ‘global $saved_user_ids;’ doesn’t seem to contain anything. I’ve tested my function with just a string and assigning a string to a variable that’s returned in a shortcode and it all works fine. But calling anything from saved_user_ids variable just returns blanks. Are you sure that’s the appropriate global variable? I can’t seem to figure this out :/

    Plugin Author Andrea Tarantini

    (@dontdream)

    Yes, the array name is right.

    The problem is that a shortcode is processed *before* the search runs, so the array is still empty. I see no solution to this problem, the only way I see is not to use a shortcode after all.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Results Page retrieve displayed members’ IDs’ is closed to new replies.