• I have a number of technicians who need to log in and see the jobs that have been assigned to them. I have already figured out how to set up the Participants Database for this with the correct fields and the import of data each day.

    And I can put their website user name into the job list that I import, so that each job has a tech name assigned (which will be the same as their log in user name). When they log in and are automatically transferred to their “Job List” page (the Participants List), is it possible that the job list is filtered to only their jobs?

    The short code ( [pdb_list] placed in the page editor) that triggers the Participants Database list page already has a filter capability, so what I want might look something like [pdb_list filter=”XXX”] where “XXX” would have to be a code that pulls in the actual User Name of the person logged in and thus filter the list to only that technician’s jobs.

    If this is possible, how would I pick up the user name of the person logged in (the “XXX” referred to above) and place that into the filter expression?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Something like the following would work

    This is how you would pick up the user_id. I’ve also shown how you can get the name and email etc from the WP backend.

    $current_user= wp_get_current_user();
    $wp_username = $current_user->user_login;
    $wp_firstname= $current_user->user_firstname;
    $wp_lastname = $current_user->user_lastname;
    $wp_email = $current_user->user_email;

    $user_id = Participants_Db::get_record_id_by_term(‘username’,$wp_username);
    $data = Participants_Db::get_participant($user_id);
    // You can access the users info in the $data array

    Now that you have the user_id you can output the data for that user, using several shortcode options. I’ve shown one below.

    [pdb_record fields=”etc,etc”,record_id=$user_id]

    Hope that helps…

    Thread Starter NeilIrving

    (@neilirving)

    Thanks Supernova42,

    Your reply is much appreciated. I will study what you have said and see if I can implement it. I am not familiar with php however, so I may need some more help. My main focus is MS Access VBA and although my knowledge is quite deep on that subject, it is very narrow in others.

    The easiest way to get a little php into your site is to use a ‘php snippet’ plugin. I use Woody Ad.

    Basically you put your php into a thing called a snippet and access it with a shortcode.

    As I see it, to get the best out of WordPress you need to have some knowledge of css and a little php. I’ve put an example below…

    <?php
    // Get the name of the current logged in user from WP
    $current_user=wp_get_current_user();
    $wp_username=$current_user->user_login;
    
    // Get the current user id from pdb
    $pdb_id=Participants_Db::get_record_id_by_term('username',$wp_username);
    
    // Get the users data from pdb which is in an array
    $data=Participants_Db::get_participant($pdb_id);
    
    // Get the names from the $data array
    //'first_name' and 'last_name' would be defined fields within pdb
    $first_name=$data['first_name'];
    $last_name=$data['last_name'];
    ?>

    Of course you can also write to the PDB and you can include shortcodes within php.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Auto Filter List on Log-In’ is closed to new replies.