Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*** The filters ****/
- <?php $categories = get_terms('roller'); ?>
- <ul class="cat-list">
- <li><a class="cat-list_item active" href="#!" data-slug="">All projects</a></li>
- <?php foreach($categories as $category) : ?>
- <li>
- <a class="cat-list_item" href="#!" data-slug="<?= $category->slug; ?>" data-type="upphovspersoner">
- <?= $category->name; ?>
- </a>
- </li>
- <?php endforeach; ?>
- </ul>
- /****** The script*******/
- <script>
- $('.cat-list_item').on('click', function(e) {
- $('.cat-list_item').removeClass('active');
- $(this).addClass('active');
- $.ajax({
- type: 'POST',
- url: '/wp-admin/admin-ajax.php',
- dataType: 'html',
- data: {
- action: 'filter_projects',
- taxonomy: $(this).data('slug'),
- },
- success: function(res) {
- $('.project-tiles').html(res);
- }
- })
- });
- </script>
- <?PHP
- /******* functoins.php *******/
- function filter_projects() {
- $postType = $_POST['type'];
- $catSlug = $_POST['taxonomy'];
- $projects = new WP_Query([
- 'post_type' => 'upphovspersoner',
- 'posts_per_page' => -1,
- 'tax_query' => [
- [
- 'taxonomy' => 'roller',
- 'field' => 'slug',
- 'operator' => 'IN'
- ],
- ]
- ]);
- $response = '';
- if($ajaxposts->have_posts()) {
- while($ajaxposts->have_posts()) : $ajaxposts->the_post();
- $response .= include('framework/upphovspersoner-item.php');
- endwhile;
- } else {
- $response = 'empty';
- }
- echo $response;
- exit;
- }
- add_action('wp_ajax_filter_projects', 'filter_projects');
- add_action('wp_ajax_nopriv_filter_projects', 'filter_projects');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement