<?php
function categories_list_func( $atts)
{
	extract(shortcode_atts(array(
		"cat" => '1'
	), $atts));
	
	 ob_start();	  
	 if($cat =='All')
	 {
		 $args = array(
				'posts_per_page'  => 10,
				'numberposts'     => 5,
				'offset'          => 0,
				'category'        => '',
				'orderby'         => 'post_date',
				'order'           => 'DESC',
				'post_type'       => 'faqs',		
				'post_status'     => 'publish',	
				);
		 $loop = new WP_Query( $args );
		echo '<div class="marginleft"><div class="container_support">';
		$counter = 1 ;
		while ($loop->have_posts() ) : $loop->the_post();
		if($counter == 4){ echo '</div><div class="continer1">';}
		 ?>
<h2 class="acc_trigger"><a href="#">
  <?php the_title(); ?>
  </a></h2>
<div class="acc_container">
  <div class="block">
    <p>
      <?php the_content();?>
  </div>
</div>
<?php
		 $counter++;
		endwhile;
		echo '</div></div><div class="clear"></div>';				
	 }
	 else
	 {
		 $args = array(
				'posts_per_page'  => 5,
				'numberposts'     => 5,
				'offset'          => 0,
				'category'        => '',
				'orderby'         => 'post_date',
				'order'           => 'DESC',
				'post_type'       => 'faqs',		
				'post_status'     => 'publish',	
				);
				$args['tax_query'][] = array(
					'taxonomy' => 'faqs_catagories',
					'field' => 'slug',
					'terms' => $cat);

		 $loop = new WP_Query( $args );
		 $i=0;
		echo '<div id="accordion">';
		while ( $loop->have_posts() ) : $loop->the_post();
			$count_posts = wp_count_posts();
		 ?>
<h3>
  <?php the_title(); ?>
</h3>
<div>
  <p>
    <?php the_content().$count_posts ;?>
  </p>
</div>
<?php
		endwhile;
		$i++;
		echo '</div>';
	 }
	$categories = ob_get_contents();
	ob_end_clean();
 return  $categories;

}
add_shortcode( 'Faqs', 'categories_list_func');

add_action('init', 'add_faq_button');
function add_faq_button() 
{
   if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) 
   {
     return;
   }
 
   if ( get_user_option('rich_editing') == 'true' ) 
   {
     add_filter( 'mce_external_plugins', 'add_faq_plugin' );
     add_filter( 'mce_buttons', 'register_faq_button' );
   } 
}
 function register_faq_button( $buttons ) 
{
	array_push($buttons, "|", "faq");
	return $buttons;
}
function add_faq_plugin( $plugin_array ) 
{
   $plugin_array['faq'] = get_template_directory_uri().'/shortcode/FAQ/faq_shortcode.js';
   return $plugin_array;
}	

?>
