<?php
$id = $block['id'];
$class = [];

if($block['align']){
    $class[] = 'align'.$block['align'];
}

$post_source = get_field('post_source');
$display_type = get_field('display_type');
$content_post = get_field('content_post');
$category = get_field('category');
$number_of_post = get_field('number_of_post') ? get_field('number_of_post') : 3;

$html = '';

if($post_source == 'post'){
    $posts = $content_post;
} else {
    $args = array(
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'taxonomy' => 'category',
                'field' => 'id',
                'terms' => $category,
                'include_children' => false,
                'operator' => 'IN'
            )
        ),
        'post_type' => 'post',
        'posts_per_page' => $number_of_post
    );

    $the_posts = new WP_Query( $args );
    if($the_posts->posts){
        $posts = $the_posts->posts;
    }
    wp_reset_postdata();
}

$html .= '<div id="'.$id.'" class="'.implode(' ', $class).'">';
    $html .= '<div class="z-post-grid-wrapper">';
        $html .= z_render_posts_grid($posts, $display_type);
    $html .= '</div>';
$html .= '</div>';

echo $html;
