Once I run this question on posts_type => "posts" it really works simply effective. However once I add my customized put up sort ‘post_type’ => ‘case-studies’, I get no outcomes.
The customized put up sort has a customized taxonomy arrange of ‘case_study_categories’. Can anybody spot what’s improper? I have been taking a look at this for 3 hours and simply do not perceive why it is not working.
filter-posts.php:
<?php
perform ajax_filter_posts_scripts() {
// Enqueue script
wp_enqueue_script('afp_script', get_template_directory_uri() . '/js/ajax/filter-posts.js', array('jquery'), null, false);
wp_localize_script( 'afp_script', 'afp_vars', array(
'afp_nonce' => wp_create_nonce( 'afp_nonce' ), // Create nonce which we later will use to confirm AJAX request
'afp_ajax_url' => admin_url( 'admin-ajax.php' ),
)
);
}
add_action('wp_enqueue_scripts', 'ajax_filter_posts_scripts', 100);
// Script for getting posts
perform ajax_filter_get_posts() {
// Confirm nonce
if( !isset( $_POST['afp_nonce'] ) || !wp_verify_nonce( $_POST['afp_nonce'], 'afp_nonce' ) )
die('Permission denied');
$knowledge = $_POST['data'];
$taxonomy = $knowledge['taxonomy'];
$posts_per_page = $knowledge['posts_per_page'];
$args = array(
'post_type' => 'case-studies',
'posts_per_page' => $posts_per_page,
);
// If taxonomy will not be set, take away key from array and get all posts
if( $taxonomy ) {
$args['category_name'] = $taxonomy;
}
$question = new WP_Query( $args );
$max = $query->max_num_pages;?>
<?php if ( $query->have_posts() ) :
// Used to rely the posts and evaluate to max to cover and present load extra button;
$index = 1;
whereas ( $query->have_posts() ) : $query->the_post();
$index++;
$featured_img_url_medium = get_the_post_thumbnail_url(get_the_ID(),'medium_large');
$id = get_the_ID();
$class = get_the_category();
$category_name = $class[0]->cat_name;?>
<a href="<?= get_permalink(); ?>" title="Read - <?php the_title(); ?>" class="dynamic-blogs__card card">
<div class="news-image-container">
<div class="hover-read-more">
<div class="text">
<i class="fal fa-chevron-circle-right"></i>
<p>Learn Now</p>
</div>
</div>
<img class="card-image lazy" src="<?= $featured_img_url_medium; ?>" alt="<?php the_title(); ?>" loading="lazy">
</div>
<div class="card-text-container">
<?php if( $category_name ) {
echo '<p class="card-category">' . $category_name . '</p>';
} ?>
<?= the_title('<h3 class="">', '</h3>'); ?>
</div>
</a><!-- Card END -->
<?php endwhile; ?>
<?php if($index <= $max ): ?>
<div class="dynamic-blogs__load-more py">
<div class="btn -ghost js-tax-filter" quantity="12">Load Extra</div>
</div>
<?php endif; ?>
<?php else: ?>
<h2>No posts discovered</h2>
<?php endif;
die();
}
add_action('wp_ajax_filter_posts', 'ajax_filter_get_posts');
add_action('wp_ajax_nopriv_filter_posts', 'ajax_filter_get_posts');
?>