Example #1
0
function ac_prepare_args_for_get_posts(&$args)
{
    // Ensure posts_per_page is a useable int value
    // Convert 'all' from UI to -1 for WP
    if (isset($args['posts_per_page']) && $args['posts_per_page'] == 'all') {
        $args['posts_per_page'] = -1;
    }
    // Allow for entire post content in excerpt
    if (isset($args['excerpt_length']) && $args['excerpt_length'] == 'all') {
        $args['excerpt_length'] = -1;
    }
    // Default the show cat filter
    if (!isset($args['show_cat_filter'])) {
        $args['show_cat_filter'] = true;
    }
    // Order.  Convert AC into WP
    // Only do this is the $args do not have a WP order_by already set
    if (!isset($args['orderby']) || !isset($args['order']) || $args['orderby'] == '' || $args['orderby'] == '') {
        $order = ac_convert_ac_order($args['ac_order']);
        $args['order'] = $order['order'];
        $args['orderby'] = $order['orderby'];
    }
    // Cats and Terms
    if (isset($args['cat']) && $args['cat']) {
        // If we have a categoy defined
        // If we have a category for filtering dont show the category filter control
        $args['show_cat_filter'] = false;
        // Filter custom taxonomy filters
        $args['tax_query'] = array(array('taxonomy' => $args['post_category'], 'field' => 'term_id', 'terms' => $args['cat']));
        // Clear the 'cat' arg for the get_posts
        $args['cat'] = null;
        unset($args['cat']);
    }
}
 protected function content($atts, $content = null)
 {
     $this->content_has_container = false;
     // Get the shortcode atrributes
     extract(shortcode_atts(array('title' => '', 'layout' => 'posts', 'cat' => '', 'posts_per_page' => 6, 'column_count' => 3, 'column_count_tile' => 3, 'ac_order' => 'order_date_desc', 'order' => '', 'orderby' => '', 'show_title' => true, 'show_excerpt' => true, 'excerpt_length' => '', 'autoplay' => 'false', 'post__in' => '', 'offset' => '', 'show_cat_filter' => '', 'css_animation' => '', 'css' => '', 'show_read_more' => true), $atts));
     // Ensure all data is in the correct format, as there might be differences between Visual Composer and WP Query
     // $post__in needs to be an array
     $post__in = trim($post__in);
     if ($post__in && !is_array($post__in)) {
         $post__in = explode(',', $post__in);
         $atts['post__in'] = $post__in;
     }
     // Merge in any plugin attributes.  This gives us a single portable set of options
     $args = array('post_type' => $this->post_type, 'post_category' => $this->post_category, 'link_to_lightbox' => $this->link_to_lightbox, 'post_status' => 'publish');
     // Expand the order by.  Don't do this if post ids have been provided
     if ($ac_order && empty($post__in)) {
         // Order.  Convert AC into WP
         $order = ac_convert_ac_order($ac_order);
         $atts['order'] = $order['order'];
         $atts['orderby'] = $order['orderby'];
     }
     // Merge the atrributes into the grid builder args
     $args = wp_parse_args($atts, $args);
     // Prepare args
     ac_prepare_args_for_get_posts($args);
     // Apple a filter based on the type
     $args = $this->filter_posts($args);
     // CSS
     $css_class = $this->build_outer_css($atts, $content);
     // Build the content
     $control = '';
     // Standard - Posts
     if ($layout == 'posts') {
         $control = ac_posts_list($args);
     } elseif ($layout == 'grid' || $layout == 'masonry') {
         $control = ac_posts_grid($args);
     } elseif ($layout == 'carousel') {
         $control = $this->get_carousel($args);
     } elseif ($layout == 'slider') {
         if (!isset($args['slider_size'])) {
             $args['slider_size'] = '3by2';
             // Default for image driver sliders
         }
         // Different style for some post types
         if ($this->post_type == 'attachment') {
             $args['slider_style'] = 'slider-gallery';
         } elseif ($this->post_type == 'ac_testimonial') {
             $args['slider_style'] = 'no-caption';
             $args['slider_size'] = 'auto-height';
             // Clear meta_key, which we normally set for sliders to _thumbnail_id to ensure only sliders with featured images are shown
             $args['meta_key'] = null;
             $args['auto_height'] = true;
             // auto height as this is content lead and not image led
         } else {
             $args['slider_style'] = 'slider-post';
         }
         $control = ac_render_posts_slideshow($args);
     } elseif ($layout == 'slick') {
         $control = ac_render_slick_carousel($args);
     } elseif ($layout == 'showcase') {
         $control = $this->get_showcase($args);
     } elseif ($layout == 'tile' || $layout == 'tile-masonry') {
         // Change the column count param
         $args['column_count'] = $args['column_count_tile'];
         $control = ac_posts_tile($args);
     }
     // Build the output
     $output = "\n\t" . '<div class="' . esc_attr($css_class) . ' ac-' . $layout . '-wrapper">';
     $output .= "\n\t" . $this->get_title($title);
     $output .= "\n\t\t" . '<div class="wpb_wrapper">';
     $output .= "\n\t\t\t" . $control;
     $output .= "\n\t\t" . '</div> ' . $this->endBlockComment('.wpb_wrapper');
     $output .= "\n\t" . '</div> ' . $this->endBlockComment($this->settings['base']);
     return $output;
 }