function wpb_hook_javascript() {?>
 <script type="text/javascript">
$('.cat-list_item').on('click', function() {
  $('.cat-list_item').removeClass('active');
  $(this).addClass('active');
  $.ajax({
    type: 'POST',
    url: '/wp-admin/admin-ajax.php',
    dataType: 'html',
    data: {
      action: 'filter_projects',
      category: $(this).data('id'),
    },
    success: function(res) {
      $('.project-tiles').html(res);
    }
  })
});
   </script>
<?php }
add_action('wp_footer', 'wpb_hook_javascript');

function filter_projects() {
  $catID = $_POST['category'];

  $ajaxposts = new WP_Query([
    'post_type' => 'post',
    'posts_per_page' => 6,
    'cat' => $catID,
  ]);
  $response = '';

  if($ajaxposts->have_posts()) {
    while($ajaxposts->have_posts()) : $ajaxposts->the_post();
	    $response .= do_shortcode('[bricks_template id="1840"]');
    endwhile;
  } else {
    $response = 'empty';
  }

  echo $response;
  exit;
}
add_action('wp_ajax_filter_projects', 'filter_projects');
add_action('wp_ajax_nopriv_filter_projects', 'filter_projects');

