2

I have a question in regards to a WordPress plugin (Bookly) that creates a Staff ID for an already created WordPress user, and hopefully, somebody may be able to help me with.

Currently Bookly adds the Staff ID incremental so each new staff ID would say Staff ID:4 then the next 5 then 6 etc, I'm looking for some code that would take the current WordPress user's ID and add that ID as the Staff ID for that user when they are creating a Staff ID for them.

Any help much appreciated.

Thanks Ryan

1
  • did you ever find a solution to this? I have the exact same problem.
    – M0rty
    Commented Jun 20, 2019 at 23:55

2 Answers 2

0

Because the database table is set up to auto increment then you can't change the ID to match user ID without redesigning the database tables. This would be fine except you wouldn't be able to update the plugin without remaking the changes each time.

8
  • Thank you for the feedback, would there be any other work around where i could match a users wordpress ID with their staff ID? The issue i have is that the users profile is displayed via a template and in the template i have shorcode to dispay the users booking module via Staff ID="1" i thought if i could have the Wordpress users ID the same as the Staff ID i could use get_userid from post / page.(<?php $postid = get_the_ID(); ?> My appoligies my coding knowledge is not too advanced Commented Oct 9, 2017 at 16:37
  • How does the plugin link staff id to user id?
    – lukgoh
    Commented Oct 9, 2017 at 16:48
  • by username and email and contact number is the details pulled from the WP user to Create a Staff ID for the user Commented Oct 9, 2017 at 18:40
  • Well if the staff ID and user name is linked then you just retrieve the user name from the staff ID then use this function: developer.wordpress.org/reference/functions/get_user_by
    – lukgoh
    Commented Oct 9, 2017 at 19:32
  • 1
    No but i can learn how to do it. TABLE "wp_ab_staff" with these colums "id" "wp_user_id" "full_name then 2nd table name "service_finder_providers" with colums "wp_user_id" "full_name" would this help you to help me Commented Oct 10, 2017 at 21:58
0
function get_user_by_staff_id($user_ID) {

    $results = $wpdb->get_results("SELECT id FROM wp_ab_staff WHERE wp_user_id = '$user_ID' LIMIT 1 ");

    $staff_id = $results;

    return $staff_id;
}

Add this to your functions.php (not Booklys!!)

Then to use it you can do this:

 <?php echo do_shortcode('[bookly-form category_id="1" service_id="4" staff_member_id="'. get_user_by_staff_id(**USER ID HERE**) .'" hide="categories,services,staff_members,week_days"]'); ?>
13
  • Thank you so much i will try this now and let you know how i get on Commented Oct 10, 2017 at 23:44
  • If i insert the_author_meta($field,$user_id); where USER ID HERE would this pull the ID from the Url and enter it here automatically ? Commented Oct 11, 2017 at 0:34
  • From the URL? So you have something like example.com?id=ID in the url?
    – lukgoh
    Commented Oct 11, 2017 at 7:16
  • yea thats correct example.com/tom-smith its the user name that appears in the url Commented Oct 11, 2017 at 9:48
  • What is the get variable? So something like $name = $_GET['id'];
    – lukgoh
    Commented Oct 11, 2017 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.