| 1 |
<?php |
| 2 |
namespace gutenify; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
class Post_List { |
| 7 |
public static function get_posts( $attributes, $props ) { |
| 8 |
$args = array( |
| 9 |
'posts_per_page' => ! empty( $attributes['query']['numberOfItems'] ) ? $attributes['query']['numberOfItems'] : 10, |
| 10 |
'post_status' => 'publish', |
| 11 |
'order' => ! empty( $attributes['query']['order'] ) ? $attributes['query']['order'] : 'desc', |
| 12 |
'orderby' => ! empty( $attributes['query']['orderBy'] ) ? $attributes['query']['orderBy'] : 'date', |
| 13 |
'suppress_filters' => false, |
| 14 |
'category__in' => array(), |
| 15 |
'post__not_in' => array( get_the_ID() ), |
| 16 |
); |
| 17 |
|
| 18 |
if ( isset( $attributes['query']['selectedCategories'] ) ) { |
| 19 |
|
| 20 |
$args['category__in'] = array_column( $attributes['query']['selectedCategories'], 'id' ); |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
if ( ! empty( $attributes['query']['tax']['category'] ) ) { |
| 25 |
|
| 26 |
$args['category__in'] = array_merge( $attributes['query']['tax']['category'], $args['category__in'] ); |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
if ( ! empty( $attributes['query']['tax']['tag'] ) ) { |
| 31 |
$args['tag__in'] = $attributes['query']['tax']['tag']; |
| 32 |
} |
| 33 |
|
| 34 |
if ( ! empty( $attributes['query']['tax']['post_tag'] ) ) { |
| 35 |
$args['tag__in'] = $attributes['query']['tax']['post_tag']; |
| 36 |
} |
| 37 |
|
| 38 |
if ( ! empty( $attributes['query']['authorIds'] ) ) { |
| 39 |
$args['author__in'] = $attributes['query']['authorIds']; |
| 40 |
} |
| 41 |
|
| 42 |
if ( ! empty( $attributes['query']['postTypes'] ) && in_array( 'attachment', $attributes['query']['postTypes'] ) ) { |
| 43 |
$args['post_status'] = 'inherit'; |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
$recent_posts = get_posts( $args ); |
| 48 |
$formatted_posts = gutenify_get_post_info( $recent_posts ); |
| 49 |
return $formatted_posts; |
| 50 |
} |
| 51 |
} |
| 52 |
|