Answer the question
In order to leave comments, you need to log in
How to fix load more in WP?
I'm doing ajax post filters + the "Show more" button according to this instruction
. The
filters work fine, but the load more button creates a problem.
If I filtered records by categories
Then, as planned, the "load more" button should load records from the filtered categories. And she loads all the records.
I know that the categories filtered by the array should be passed here:
function misha_loadmore_ajax_handler(){
...
$args['category_name'] = 'services, categories';
...
}
<?php
$cat_services = get_category_by_slug('services');
$categories_services = get_categories( [
'taxonomy' => 'category',
'type' => 'post',
'parent' => $cat_services->term_id,
'hide_empty' => 0,
] );
echo '<h3>'. $cat_services->cat_name .'</h3>';
if( $categories_services ){
echo '<ul class="cat-check-list" id="categoryfilter-1" name="categoryfilter-1">';
foreach( $categories_services as $cat ){
echo '<li><div class="checkbox-custom"><span><label for="category_'. $cat->cat_ID .'"><input type="checkbox" id="category_'. $cat->cat_ID .'" name="category_'. $cat->cat_ID .'" />' . $cat->name . '</label></span></div></li>';
}
echo '</ul>';
}
$cat_categories = get_category_by_slug('categories');
$categories_categories = get_categories( [
'taxonomy' => 'category',
'type' => 'post',
'parent' => $cat_categories->term_id,
'hide_empty' => 0,
] );
echo '<h3>'. $cat_categories->cat_name .'</h3>';
if( $categories_categories ){
echo '<ul class="cat-check-list" id="categoryfilter-2" name="categoryfilter-2">';
foreach( $categories_categories as $cat ){
echo '<li><div class="checkbox-custom"><span><label for="category_'. $cat->cat_ID .'"><input type="checkbox" id="category_'. $cat->cat_ID .'" name="category_'. $cat->cat_ID .'" />' . $cat->name . '</label></span></div></li>';
}
echo '</ul>';
}
?>
Answer the question
In order to leave comments, you need to log in
On the client side, collect the selected categories and transfer to the server
data : {
'action': 'loadmore', // the parameter for admin-ajax.php
'query': misha_loadmore_params.posts, // loop parameters passed by wp_localize_script()
'page' : misha_loadmore_params.current_page // current page
'categories': ...
},
$args['category_name'] = $_POST['categories']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question