Beispiel #1
0
function us_ajax_portfolio()
{
    if (!isset($_POST['ids']) or !is_string($_POST['ids']) or empty($_POST['ids'])) {
        die('This ajax method should be used with a comma-separated list of IDs');
    }
    // Preparing query
    $query_args = array('post_type' => 'us_portfolio', 'post_status' => 'publish', 'post__in' => array_map('absint', explode(',', $_POST['ids'])), 'orderby' => 'post_in', 'nopaging' => TRUE);
    us_open_wp_query_context();
    global $wp_query;
    $wp_query = new WP_Query($query_args);
    if (!have_posts()) {
        // TODO Move to a separate variable
        _e('No portfolio items were found.', 'us');
        return;
    }
    // Filtering $template_vars, as is will be extracted to the template as local variables
    $template_vars = shortcode_atts(array('metas' => array('title')), us_maybe_get_post_json('template_vars'));
    while (have_posts()) {
        the_post();
        us_load_template('templates/portfolio/listing-post', $template_vars);
    }
    // We don't use JSON to reduce data size
    die;
}
Beispiel #2
0
    $wpdb_query .= 'WHERE `ID` IN (' . $items_ids . ') AND `post_type`=\'us_portfolio\' AND `post_status`=\'publish\' ';
    $wpdb_query .= 'ORDER BY ' . ($orderby == 'rand' ? 'RAND()' : '`post_date` ' . $order);
    $tile_order = array('*' => array_map('absint', $wpdb->get_col($wpdb_query)));
    if ($filter == 'category') {
        $tile_order = array_merge($tile_order, array_fill_keys(array_keys($categories_names), array()));
        foreach ($tile_order['*'] as $elm_id) {
            foreach ($items_categories[$elm_id] as $category_slug) {
                $tile_order[$category_slug][] = $elm_id;
            }
        }
    }
    // Overloading the query by selecting the certain IDs
    $query_args['post__in'] = $tile_order['*'];
    $query_args['orderby'] = 'post__in';
}
us_open_wp_query_context();
global $wp_query;
$wp_query = new WP_Query($query_args);
if (!have_posts()) {
    // TODO Move to a separate variable
    _e('No portfolio items were found.', 'us');
    return;
}
$filter_html = '';
$filter = isset($filter) ? $filter : 'none';
if ($filter == 'category') {
    // $categories_names already contains only the used categories
    if (count($categories_names) > 1) {
        $classes .= ' with_filters';
        $filter_html .= '<div class="g-filters"><div class="g-filters-list">';
        $filter_html .= '<div class="g-filters-item active" data-category="*">' . __('All', 'us') . '</div>';