Hi everybody,
Im trying to make an ajax post filter by category.
So im following this tutorial: https://weichie.com/blog/wordpress-filter-posts-with-ajax/
So my problem is this hook:
add_action(‘wp_ajax_filter_projects’, ‘filter_projects’);
add_action(‘wp_ajax_nopriv_filter_projects’, ‘filter_projects’);function filter_projects() {
$catSlug = $_POST[‘category’];$ajaxposts = new WP_Query([ 'post_type' => 'post', 'posts_per_page' => -1, 'category_name' => $catSlug, 'orderby' => 'menu_order', 'order' => 'desc', ]); $response = ''; if($ajaxposts->have_posts()) { while($ajaxposts->have_posts()) : $ajaxposts->the_post(); $response .= 'Results'; endwhile; } else { $response = 'empty'; } echo $response; exit;
}
When i put the following code in /functions.php it works, but when i move it to app/setup.php it doesn’t work.
Any idea?
is there any example on how to use ajax to call posts with Sage 10 ?
Thanks