Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Shortcode to display fastforests_status CPT
- add_shortcode('fastforests_status', 'fastforests_status_listing');
- function fastforests_status_listing($atts, $content, $code) {
- $ds_args = array(
- 'post_type' => 'fastforests_status',
- 'no_found_rows' => true,
- 'post_status' => 'publish',
- 'ignore_sticky_posts' => true,
- 'posts_per_page' => -1,
- );
- $ds = new WP_Query( $ds_args );
- if ($ds->have_posts()) {
- $current_date = time();
- $due_date_close = 60 * 60 *24 * 40; // 40 days.
- $status_table = '<table id="fastforests_status" class="tablesorter"><thead><tr><th>Task</th><th>Owner</th><th>% complete</th><th>Due Date</th></tr></thead><tbody>';
- while ( $ds->have_posts() ) : $ds->the_post();
- $task_class = 'task_ok';
- $date_due = DateTime::createFromFormat('Ymd', get_field('date_due'));
- $percent_complete = get_field('percent_complete');
- $time_until_task_due = $date_due->getTimestamp() - $current_date;
- if ($percent_complete == 100) {
- $task_class = 'task_complete';
- } elseif ($time_until_task_due < $due_date_close) {
- $task_class = 'task_nearly_due';
- if ($time_until_task_due < 0) {
- $task_class = 'task_overdue';
- }
- }
- $status_table .= sprintf('<tr class="%s"><td>%s</td><td>%s</td><td>%s %%</td><td>%s</td></tr>%s', $task_class, get_the_title(), get_field('who'), $percent_complete, $date_due->format('d-m-Y'), "\n");
- endwhile;
- $status_table .= '</tbody></table>';
- }
- wp_reset_postdata();
- return $status_table;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement