/**
 * Register a shortcode for location tasks.
 * This just makes it stupid easy to drop into a page.
 *
 * Usage: [wanderlist-location], by default will show current location.
 *
 * Pass the "show" parameter to show different information.
 * For now, [wanderlist-location show=current] will show current (or most recent) location,
 * [wanderlist-location show=countries] will show total number of countries.
 */
function wanderlist_location_shortcode($atts, $content = null)
{
    $a = shortcode_atts(array('show' => 'current'), $atts);
    if ('current' === $a['show']) {
        return '<span class="wanderlist-current-location">' . wanderlist_get_current_location('text') . '</span>';
    }
    if ('countries' === $a['show']) {
        return '<span class="wanderlist-country-count">' . wanderlist_count('countries') . '</span>';
    }
}
Пример #2
0
/**
 * Show a list of locations.
 *
 * This will default to showing all upcoming locations.
 * Passing the limit and show params will change its output.
 */
function wanderlist_list_locations($limit = null, $show = 'default')
{
    $options = get_option('wanderlist_settings');
    if ('all' === $show) {
        $order = 'DESC';
    } elseif ('past' === $show) {
        $order = 'DESC';
        $compare = '<=';
    } elseif ('upcoming' === $show) {
        $order = 'ASC';
        $compare = '>';
    } elseif ('default' === $show) {
        $order = 'ASC';
        $compare = '>';
        $limit = $limit - 1;
    }
    $args = array('post_type' => 'wanderlist-location', 'post_status' => array('future', 'publish'), 'posts_per_page' => $limit, 'orderby' => 'meta_value post_date', 'meta_key' => 'wanderlist-arrival-date', 'meta_value' => wanderlist_today(), 'meta_compare' => $compare, 'order' => $order, 'tax_query' => array(array('taxonomy' => 'post_tag', 'field' => 'term_id', 'terms' => $options['wanderlist_home_tag'], 'operator' => 'NOT IN')));
    $location_query = new WP_Query($args);
    $locations = '<dl>';
    // If we're not passing an upcoming/past parameter, show today's location
    if ('default' === $show) {
        $locations .= wanderlist_get_current_location('coords');
    }
    // Generate a list of posts
    while ($location_query->have_posts()) {
        $location_query->the_post();
        $locations .= wanderlist_format_location(get_the_ID());
        wp_reset_postdata();
    }
    $locations .= '</dl>';
    return $locations;
}