Пример #1
0
function us_ajax_blog()
{
    // Filtering $template_vars, as is will be extracted to the template as local variables
    $template_vars = shortcode_atts(array('query_args' => array(), 'layout_type' => 'large', 'metas' => array(), 'content_type' => 'none', 'show_read_more' => FALSE, 'pagination' => 'regular', 'el_class' => ''), us_maybe_get_post_json('template_vars'));
    // Filtering query_args
    if (isset($template_vars['query_args']) and is_array($template_vars['query_args'])) {
        // Query Args keys, that won't be filtered
        $allowed_query_keys = array('category_name', 'year', 'monthnum', 'day', 'tag', 's', 'paged', 'orderby', 'posts_per_page', 'post_type');
        foreach ($template_vars['query_args'] as $query_key => $query_val) {
            if (!in_array($query_key, $allowed_query_keys)) {
                unset($template_vars['query_args'][$query_key]);
            }
        }
        if (!isset($template_vars['query_args']['s']) and !isset($template_vars['post_type'])) {
            $template_vars['query_args']['post_type'] = 'post';
        }
        // Providing proper post statuses
        $template_vars['query_args']['post_status'] = array('publish' => 'publish');
        $template_vars['query_args']['post_status'] += (array) get_post_stati(array('public' => TRUE));
        // Add private states if user is capable to view them
        if (is_user_logged_in() and current_user_can('read_private_posts')) {
            $template_vars['query_args']['post_status'] += (array) get_post_stati(array('private' => TRUE));
        }
        $template_vars['query_args']['post_status'] = array_values($template_vars['query_args']['post_status']);
    }
    // Passing values that were filtered due to post protocol
    us_load_template('templates/blog/listing', $template_vars);
    // We don't use JSON to reduce data size
    die;
}
Пример #2
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;
}