<?php
/* Template Name: 我的收藏  */

global $wpdb;
$wpdb->collection = $wpdb->prefix.'collection';
$user_id        = get_current_user_id();
$all_collections = $wpdb->get_results( $wpdb->prepare("select post_id from $wpdb->collection where user_id = %d LIMIT 0,10", $user_id ) );

if( $all_collections ){
	foreach ($all_collections as $key => $value) {
		$collections_posts[] = $value->post_id;
	}

	$args = array(
		'post_type' => 'post',
		'post__in' => $collections_posts,
		'ignore_sticky_posts' => 1,
	);
	$collection_posts = new WP_Query($args);
}
?>

<section class="card">
	<div class="ceo-container ceo-margin-medium-bottom">
		<div class="card" ceo-grid>
			<?php
			if( $collection_posts && $collection_posts->have_posts() ){
				while( $collection_posts->have_posts() ) : $collection_posts->the_post();
			?>

			<div class="ceo-width-1-1@s ceo-width-1-2 ceo-width-1-4@xl">
				<?php get_template_part( 'template-parts/home/loop', 'card' ); ?>
			</div>

			<?php endwhile; ?>

			<?php }else{ ?>

			<p>抱歉，您目前没有收藏任何文章～</p>
			<?php } ?>


		</div>
	</div>
</section>
