add_action('wp_ajax_load_more_posts', 'load_more_posts');
add_action('wp_ajax_nopriv_load_more_posts', 'load_more_posts');
function load_more_posts() {
$paged = $_POST['page'];
$catid = $_POST['catid'];
$args = array(
'post_type' => 'case_study',
'posts_per_page' => 3,
'order' => 'ASC',
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'case_study_category',
'field' => 'slug',
'terms' => $catid,
)
)
);
$query = new WP_Query($args);
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
$postid = get_the_ID();
$categories = get_the_category($postid);
$terms = get_the_terms($postid, 'case_study_category');
$term_slug = $terms[0]->slug;
?> <div class="mix <?php echo esc_attr($term_slug); ?> product-list filter-list">
<div class="filter-case-image-sec"><a title="click to zoom-in" href="<?php echo esc_url(get_the_post_thumbnail_url()); ?>?text=<?php echo esc_attr($term_slug); ?> - Zoom-image-1" itemprop="contentUrl" data-size="1200x600">
<img src="<?php echo esc_url(get_the_post_thumbnail_url()); ?>?text=<?php echo esc_attr($term_slug); ?> - Thumbnail-image-1" itemprop="thumbnail" alt="Image description" />
</a></div>
<div class=" detail-container">
<div class="title-holder">
<div class="main-title"><?php the_title(); ?></div>
<div class="additional-buttons additional-content">
<?php the_content();?>
</div>
</div>
<div class="redirect-button"><a href="<?php the_permalink();?>"></a></div>
</div>
</div>
<?php
endwhile;
endif;
wp_reset_postdata();
die();
}
add_action('wp_ajax_filterpost', 'filterpost');
add_action('wp_ajax_nopriv_filterpost', 'filterpost');
function filterpost() {
$portfoliopostslug = $_POST['portfoliopostid'];
$paged = $_POST['page'];
$args = array(
'post_type' => 'case_study',
'posts_per_page' => 3,
'order' => 'ASC',
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'case_study_category',
'field' => 'slug',
'terms' => $portfoliopostslug,
)
)
);
$query = new WP_Query($args);
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
$postid = get_the_ID();
$categories = get_the_category($postid);
$terms = get_the_terms($postid, 'case_study_category');
$term_slug = $terms[0]->slug;
?>
<div class="mix <?php echo esc_attr($term_slug); ?> product-list filter-list">
<div class="filter-case-image-sec">
<a title="click to zoom-in" href="<?php echo $portfolio_video_url ? esc_url($portfolio_video_url) : esc_url(get_the_post_thumbnail_url()); ?>?text=<?php echo esc_attr($term_slug); ?> - Zoom-image-1" itemprop="contentUrl" data-size="1200x600">
<img src="<?php echo esc_url(get_the_post_thumbnail_url()); ?>?text=<?php echo esc_attr($term_slug); ?> - Thumbnail-image-1" itemprop="thumbnail" alt="Image description" />
</a>
</div>
<div class=" detail-container">
<div class="title-holder">
<div class="main-title"><?php the_title(); ?></div>
<div class="additional-buttons additional-content">
<?php the_content();?>
</div>
</div>
<div class="redirect-button"><a href="<?php the_permalink();?>"></a></div>
</div>
</div>
<?php
endwhile;
endif;
wp_reset_postdata();
die();
}
<section class="black-wrap-section">
<div class="container">
<nav class="controls filter-container btn-control">
<?php
if (
$terms = get_terms(
array(
'taxonomy' => 'case_study_category',
'orderby' => 'name'
)
)
):
foreach ($terms as $term): ?>
<button type="button " class="control filter-btn" id="<?php echo $term->slug; ?>"><?php echo $term->name; ?></button>
<?php endforeach;
endif;
?>
</nav>
</div>
</section>