Title: A Filtering Problem
Last modified: February 18, 2018

---

# A Filtering Problem

 *  Resolved [supernova42](https://wordpress.org/support/users/supernova42/)
 * (@supernova42)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/)
 * Basically for simplicity my database might be reduced to the following fields
   [
   user_name][activity][leader_for_activity]
 * The club has 2000 members with about 100 activities available. 75 members are
   appointed activity leaders and the activity they are responsible for is held 
   in [leader_for_activity]. (I realise that there will be a lot of empty fields).
   There are actually 10 activity fields [activity_1] to [activity_10] but for simplicity
   I have just shown just 1 activity field [activity]. The activity leaders have
   been designated a different role to that of members.
 * Basically, I would like the activity leaders to be able to see only the members
   who are enrolled in the activity that they are responsible for. Using the wp_get_current_user()
   I can get the user_name and use the shortcode
 * echo do_shortcode(‘[pdb_list filter=”username=Drango” fields=”leader_for_activity”]’);
 * to get the name of the activity. I now want to list the names of all members 
   who have enrolled in that activity
 * An ideal list would look like
 * [Fred Jones] [Backgammon]
    …names of all members enrolled on Backgammon here ………
 * Is there any way I can do this preferably without using Templates?
 * I hope all that makes sense.
 * Many Thanks

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

 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/#post-9990884)
 * It is possible to do something like this by using a different shortcode for each
   part of the page.
 *  Thread Starter [supernova42](https://wordpress.org/support/users/supernova42/)
 * (@supernova42)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/#post-9996625)
 * I am so close to finding a solution to this. I did as you said which was
 * [insert_php]
    // Get the users login name $current_user = wp_get_current_user();
   $user_name=$current_user->user_login;
 * /* Use the login name to find the activity. I used the responsive template but
   removed the pdb-field-title so that I could obtain just the activity name */
 * $activity=do_shortcode(‘[pdb_list template=myresponsive filter=”username=’.$user_name.'”
   fields=”group_1″]’);
 * /* I get the Activity Name but when slotted into my next shortcode it doesn’t
   work */
 * echo do_shortcode(‘[pdb_list filter=”group_1=’.$activity.'”]’);
 * I check the $activity string with strlen($activity) and it appears to be 715 
   characters long. I tried trimming the string but I cannot extract the name of
   the activity from the string. I checked the $activity string and it seems to 
   contain html or CSS code which doesn’t show up and which I cannot get rid of.
 * Please can you give me a few pointers.
 * Many Thanks…
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/#post-10000070)
 * I don’t know how you are assigning a value to the $activity variable, so I can’t
   say what the problem is. You must assign that variable so that it has a string
   that will match one of the activities you have defined.
 *  Thread Starter [supernova42](https://wordpress.org/support/users/supernova42/)
 * (@supernova42)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/#post-10000122)
 * I’m assigning values to the $activity variable using a drop-down list in the 
   Manage Database Fields.
 * Part of the drop-down list is
 * null_select::None,GAMES & PASTIMES ::optgroup,Backgammon::Backgammon,Bridge::
   Bridge,Bridge Duplicate 1::Bridge Duplicate 1,Bridge Duplicate 2::Bridge Duplicate
   2,Bridge Duplicate 3::Bridge Duplicate 3,Cards For Fun::Cards For Fun,Cribbage::
   Cribbage,Cryptic Crackers::Cryptic Crackers,Mahjong for Beginners::Mahjong for
   Beginners,GENERAL INTEREST ::optgroup,Armchair Travel::Armchair etc etc
 * Cheers
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/#post-10000132)
 * OK, well that doesn’t answer my question, because I don’t see how you’re assigning
   the $activity variable value. You just need to make sure that you’re getting 
   the value you want into the $activity variable.
 *  Thread Starter [supernova42](https://wordpress.org/support/users/supernova42/)
 * (@supernova42)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/#post-10000169)
 * I have created a field called activity_1. The value for activity_1 is selected
   from that drop-down menu.
 * I then use $activity=do_shortcode(‘[pdb_list template=myresponsive filter=”username
   =’.$user_name.'” fields=”activity_1″]’);
 * This gives me the value of the variable stored in activity_1 but it seems to 
   have lots of other hidden characters. If I do an echo strlen($activity); it gives
   me a value of 459.
 * Cheers
 *  Plugin Author [xnau webdesign](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/#post-10000429)
 * OK, well, you’re dumping the output of the list shortcode into your variable,
   so that’s going to include a whole bunch of HTML. You just want the value of 
   that single field.
 * A more straightforward way to get that value is to get your record ID, then get
   the record data and use the field value from that, like this:
 *     ```
       <?php
       $record_id = Participants_Db::get_record_id_by_term('username', $user_name);
       $record = Participants_Db::get_participant( $record_id );
       $activity = $record['activity_1'];
       ?>
       ```
   
 * now you have your $activity value and can show your filtered list.
 *  Thread Starter [supernova42](https://wordpress.org/support/users/supernova42/)
 * (@supernova42)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/#post-10003461)
 * Absolutely Fantastic – This little routine allows me to get the value of any 
   variable within the database. It does exactly what I want.
    Many Thanks Once 
   again for a superb plugin.

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

The topic ‘A Filtering Problem’ is closed to new replies.

 * ![](https://ps.w.org/participants-database/assets/icon-256x256.jpg?rev=1389807)
 * [Participants Database](https://wordpress.org/plugins/participants-database/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/participants-database/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/participants-database/)
 * [Active Topics](https://wordpress.org/support/plugin/participants-database/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/participants-database/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/participants-database/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [supernova42](https://wordpress.org/support/users/supernova42/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/a-filtering-problem/#post-10003461)
 * Status: resolved