Pulling the next 10 upcoming appointments into a dashboard widget

Hey guys, hope all is well.

Currently working on a big muti-site project. I have installed and am planning to use the appointments+ plugin, all looks good so far.

One thing I have done to my users sites is add a number of custom dashboard widgets containing info. I would like to pull the next 10 (or however many) upcoming appointments into a dash widget.

I have already created the widget and have the table displaying correctly with all the correct bits of PHP in there to display the appointments.

I am looking for some help in getting the actual data into the table though. I am guessing a custom SQL command would work?

Here is what I have so far:

// Dashboard - Upcoming Appointments

function dashboard_widget_function_appointments() {

echo 'A summary of your upcoming appointments.';

echo '<table cellspacing="0" class="widefat"><thead><tr>';

echo '<th class="manage-column column-date app-column-" id="date" scope="col">Date/Time</th>';

echo '<th class="manage-column column-client app-column-" id="column" scope="col">Client</th>';

echo '<th class="manage-column column-service app-column-" id="service" scope="col">Service</th>';

echo '<th class="manage-column column-provider app-column-" id="provider" scope="col">Provider</th>';

echo '<th class="manage-column column-status app-column-" id="status" scope="col">Status</th>';

echo '</tr></thead><tfoot><tr><tbody>';

if($apps) {

foreach($apps as $key => $app) {

echo '<tr valign="middle" class="alternate app-tr">';

echo '<td class="column-date">';

echo mysql2date($this->datetime_format, $app->start);

echo '</td>

<td class="column-user">';

echo $this->get_client_name( $app->ID );

echo '<div class="row-actions">
<a href="javascript:void(0)" class="app-inline-edit">menu options here</a>
<img class="waiting" style="display:none;" src="light.gif" alt="light gif">

<td class="column-service">';

echo $this->get_service_name( $app->service );

echo '</td>
<td class="column-worker">';

echo $this->get_worker_name( $app->worker );

echo '</td>
<td class="column-status">';

if(!empty($app->status)) {
echo $app->status;

} else {

echo __('None yet.','appointments');


echo '</td>


else {

echo'<tr valign="middle" class="alternate" >

<td colspan="5" class="noappointments" scope="row">No appointments have been found - <a href="#">Add an appointment now</a></td>



echo '</tr>


If you could help me add the remaining code in order to get the correct data from the database that would be much appreciated. I am more of a front end developer so struggle a little with php/sql.

In another dash widget I have the following code, and I am guessing I need something similar for this also (if this is any help):

global $psts, $wpdb, $current_site, $blog_id, $current_user;
$levels = (array)get_site_option('psts_levels');
$current_level = $psts->get_level($blog_id);
$expire = $psts->get_expire($blog_id);
$result = $wpdb->get_row("SELECT * FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'");

All I actually need to display are the next 10 appointments based on date. it sounds pretty simple when I say it like that.

Thanks for any help! )

  • PC
    • WPMU DEV Initiate


    Greetings and thanks for posting on the forums.

    I am not a developer so the right person for this would be @vladislav. Let me call him on this thread and seek his assistance.

    It might be an idea for adding a upcoming appointments widget for the plugin :slight_smile:

    Cheers, PC

  • Vladislav
    • Dead Eye Dev


    Since the appointments are kept in a separate table, a custom SQL query will work for this purpose just fine. Perhaps something along the lines of:

    global $wpdb, $appointments;
    $sql = $wpdb->prepare("SELECT * FROM {$appointments->app_table} " .
    "WHERE status IN('paid','confirmed') " .
    "AND UNIX_TIMESTAMP(start) > %d " .
    "ORDER BY start LIMIT 0, 10",
    $future = $wpdb->get_results($sql);

    This will get ten appointments with start date in the future, and which are either paid for or confirmed. The variable $future will contain the array with results. If you need to check a specific date instead of current date, just use something like strtotime instead of time() call as an argument to $wpdb->prepare().

  • ffdltd
    • Design Lord, Child of Thor

    Excellent, thank you very much. I can print the array and the data is there.

    Would you be able to help me output this in the correct manor please?

    I currently have this, but it is not working (I told you I was rubbish with this):

    if($future) {

    foreach($future as $key => $app) {

    echo '<tr valign="middle" class="alternate app-tr">';

    echo '<td class="column-date">';

    echo mysql2date($datetime_format, $app->start);

    echo '</td>

    <td class="column-user">';

    echo $get_client_name( $app->ID );

    and so on…

    I’m guessing it needs to link up to get the users name from the ID etc too?

    Thanks again, almost there :slight_smile:

  • Vladislav
    • Dead Eye Dev


    I’m glad I was able to help. Now, to sort out the displaying issue, perhaps something like this would work?

    $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
    if(!empty($future)) {
    echo '<table>';
    foreach($future as $key => $app) {
    echo '<tr valign="middle" class="alternate app-tr">';
    echo '<td class="column-date">' . mysql2date($datetime_format, $app->start, true) . '</td>';
    echo '<td class="column-user">' . $appointments->get_client_name( $app->ID ) . '</td>';
    echo '<td class="column-service">' . $appointments->get_service_name( $app->service ) . '</td>';
    echo '<td class="column-worker">' . $appointments->get_worker_name( $app->worker ) . '</td>';
    echo '</tr>';
    echo '</table>';

    It worked for me with the code I posted above – note the use of the $appointments global variable (we declared it as global in the previous snippet). Outside Appointments main class, you’ll have to use that instead of $this variable to refer to Appointments class functionality.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.