• I have a record with 5 fields within each record called group_1, group_2 etc

    I use the fields to store sporting activities like bowls, tennis, squash etc.

    The activities can be in any of the fields.
    i.e. tennis might have been saved in group_1 or group_2 or group_3 etc

    How can I use the filter to list all the members who have enrolled for tennis. I have tried the piping command…

    [pdb_list filter=”group_1=tennis”] works fine for just Group_1

    [pdb_list filter=”group_1=tennis | group_2=tennis”] does not work

    Can you give me some pointers please

    Many Thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter supernova42

    (@supernova42)

    By the way I am selecting my activity from a drop-down list

    Thread Starter supernova42

    (@supernova42)

    Got it. I left a space either side of the piping command.
    Thanks

    Thread Starter supernova42

    (@supernova42)

    This is my shortcode

    [pdb_list orderby=last_name filter=”group_1=Backgammon|group_2=Backgammon|group_3=Backgammon|group_4=Backgammon|group_5=Backgammon” fields=”first_name, last_name,group_1,group_2,group_3,group_4,group_5″]

    To save me repeating this shortcode lots of times for all the activities I have available (I have 100 activities by the way) can I use a variable in place of where I have Backgammon and pass an Activity to that variable within the shortcode from a drop-down menu on the front end.

    Thanks

    Plugin Author xnau webdesign

    (@xnau)

    Yes, you can use a variable in a shortcode, but you have to use php code to do it.

    You can put php code in your content using a php plugin, or you can create a special shortcode for the purpose. You can also do this using a custom WP template.

    Get the “activity” value into a variable named $activity, then you can put it into the shortcode like this:

    <?php echo do_shortcode('[pdb_list orderby=last_name filter=”group_1='.$activity.'|group_2='.$activity.'|group_3='.$activity.'|group_4='.$activity.'|group_5='.$activity.'” fields=”first_name, last_name,group_1,group_2,group_3,group_4,group_5″]'); ?>

    Thread Starter supernova42

    (@supernova42)

    Hi Roland

    Thank you for your help it is much appreciated.
    I created a file called testlist.php
    You can see it here https://u3aswansea.co.uk/testlist.php

    This is the code for my file
    <?php
    echo “Hello, World!”;
    $activity=”Backgammon”;
    echo $activity;
    echo do_shortcode(‘[pdb_list orderby=last_name filter=”group_1=’.$activity.’|group_2=’.$activity.’|group_3=’.$activity.’|group_4=’.$activity.’|group_5=’.$activity.’” fields=”first_name, last_name,group_1,group_2,group_3,group_4,group_5″]’);
    ?>

    This is the output I got.

    Hello, World!Backgammon
    Fatal error: Uncaught Error: Call to undefined function do_shortcode() in /home/najad136/public_html/u3aswansea.co.uk/testlist.php:5 Stack trace: #0 {main} thrown in /home/najad136/public_html/u3aswansea.co.uk/testlist.php on line 5

    I thought I would try this mock up before moving on but unfortunately it doesn’t work for me. Can you give me some pointers please.

    Many Thanks

    PS
    I did initially try a php code plugin but that didn’t work either and that’s why I thought I would try this mockup.

    Plugin Author xnau webdesign

    (@xnau)

    That php code is using a function provided by WordPress, so that means you have to use it either in a template or as a shortcode…or use a “insert php” plugin. As a standalone script, it won’t work.

    Thread Starter supernova42

    (@supernova42)

    I’ve got it working now. I think I might have had an extra space somewhere which was rather odd. I did initially put the code inside an AddOn which I use for all my filters and extra code etc, so I guess it was inside WordPress. Would that be a better option rather than use php plugins? It’s just that I’ve read that some php plugins can leave the site open to hacking. However, if is was inside my AddOn I’m not sure how I would use it.

    The only problem I have at the moment is searching for activities which have a space(s). It finds ‘Backgammon’, ‘Darts’ ok but looking for ‘Creative Writing’ brings up the whole list. Any thoughts how I get ’round this?

    I’ve been reading your blog etc which I must say is rather interesting…

    Many Thanks

    Plugin Author xnau webdesign

    (@xnau)

    As ling as you have your filter enclosed in quotes, the space will be part of the filter…

    [pdb_list filter=”activity=Creative Writing”]

    will filter for the term “Creative Writing”

    If you want to see how the filter is working, set up your PHP error log, turn WP_DEBUG on and look at the log after loading the page.

    Thread Starter supernova42

    (@supernova42)

    Using the shortcode you showed me which was

    echo do_shortcode(‘[pdb_list filter=”group_1=’.$activity.’|group_2=’.$activity.’|group_3=’.$activity.’|group_4=’.$activity.’|group_5=’.$activity.’” fields=”first_name,last_name]’);

    I can list all the members who have subscribed for say darts in any of the 5 groups.

    I can do a mockup of this by adding $activity=”Darts”; before the shortcode – but of course I need to select the activity from the front end so I have added a drop down menu as…

    [insert_php]
    $activity=array(“Anthropology”,”Armchair Travel”,”Darts” etc etc “);
    echo ‘<select name=”myactivity”>’;
    for ($i=0; $i<count($activity); $i++)
    {echo ‘<option value=$activity[$i]>’ . $activity[$i] . ‘</option>’;}
    echo ‘</select>’;
    [/insert_php]

    The drop down menu is loaded from the array with almost 100 activities. All is great but how do I get the value that has been selected from the drop down menu into the shortcode.

    I’ve been on this for ages using $_GET and $_POST etc but with no luck.

    Do you think you might give me a few pointers.

    Many Thanks

    Plugin Author xnau webdesign

    (@xnau)

    The problem is that the page has to refresh in order to show the list. It will get a bit complicated to try to do it this way, but this article explains how to place your filter terms into a URL:

    Creating Links to Show a List Result

    I have a plugin that will do this for you: Combo Multisearch, it doesn’t provide a dropdown, but a space to type, the it autosuggests from the list of options so the user can pick one…then it shows the resulting list.

    Thread Starter supernova42

    (@supernova42)

    Hi Roland
    For me I think the Participants Database is one of the best plugins available – I find it so useful and so inspiring that I’ve now started to learn php. I’ve managed to get the routine working and have shown it below in case other users might be interested. After making a selection from the drop-down menu the user has to press SUBMIT – Not perfect but the best I’ve managed so far. Ideally, I would like to lose the SUBMIT button and just have the list displaying from a selection in the Drop Down menu.
    Many Thanks

    [insert_php]
    $activities=array(“Anthropology”,”Armchair Travel”,”Art History”,”Autobiography”,”Backgammon”,”Ballroom for Beginners”);

    //Fill drop down menu with values from array
    echo “<form>”;
    echo ‘<select name=”activity”>’;
    for($i=0; $i<count($activities); $i++)
    {
    echo ‘<option value=”‘ . ($i+1) . ‘” >’ . $activities[$i];
    }
    echo ‘</select>’;
    echo “<form>”;

    echo “<input type=’submit’>”;
    $activity_id=$_REQUEST[‘activity’];

    //Make selection from array
    $activity=$activities[$activity_id-1];

    //Display the selected List
    echo “<br/> <br/>”;
    echo “The Following Members are in the [” . $activity . “] Group”;

    echo do_shortcode(‘[pdb_list filter=”group_1=’.$activity.’|group_2=’.$activity.’|group_3=’.$activity.’|group_4=’.$activity.’|group_5=’.$activity.’|group_6=’.$activity.’|group_7=’.$activity.’|group_8=’.$activity.’|group_9=’.$activity.’|group_10=’.$activity.'” fields=”role,title,initials,first_name,last_name,zip,membership”]’);
    [/insert_php]

    Plugin Author xnau webdesign

    (@xnau)

    Very good, glad you got it working.

    To avoid the user having to press submit, you need to use javascript, which can trigger the form submission when an item is selected in the dropdown.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Using Filters’ is closed to new replies.