You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
cosmopet-architecture/wp-content/themes/cosmopet/modules/author/module-ajax-controller.php

35 lines
1.0 KiB

<?php
include_module('author');
function get_author_posts() {
$author_id = isset($_POST['author_id']) ? sanitize_text_field($_POST['author_id']) : '';
$all_posts = Timber::get_posts([
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => 'post_author',
'value' => $author_id,
'compare' => '='
]
]
]);
if ($all_posts instanceof \Timber\PostQuery || $all_posts instanceof \Timber\PostCollection) {
$all_posts = $all_posts->get_posts();
}
$remaining_posts = array_slice($all_posts, 9);
$context = Timber::context();
$context['posts'] = $remaining_posts;
Timber::render('blog_author/author-posts-list-block.twig', $context);
wp_die();
}
add_action('wp_ajax_get_author_posts', 'get_author_posts');
add_action('wp_ajax_nopriv_get_author_posts', 'get_author_posts');