WordPress Snippet

ワードプレスをカスタマイズしよう

Date Query

$args の指定の仕方は、どちらがいいのかなぁ?

$args= array(
	'post_type'		=> 'post',
	'post_status'	=> 'publish',
	'posts_per_page'=> -1,
	'date_query'	=> array(
		array(
			'inclusive'	=> true,
			'after'		=> date( 'Y-m-d', strtotime( 'last sunday -1 week' ) ) ),
		array(
			'inclusive'	=> true,
			'before'	=> date( 'Y-m-d', strtotime( 'last saturday' ) ) ),
	)
);
$args	= array(
	'post_type'		=> 'post',
	'post_status'	=> 'publish',
	'posts_per_page'=> -1,
	'date_query'	=> array(
		array(
			'compare'	=> 'BETWEEN',
			'inclusive'	=> true,
			'after'		=> date( 'Y-m-d', strtotime( 'last sunday -1 week' ) ),
			'before'	=> date( 'Y-m-d', strtotime( 'last saturday' ) ),
		)
	)
);
$query= new WP_Query( $args );

foreach ( $query->posts as $v ) {

	$html= '<p>%1$s %2$s</p>';
	printf( $html, $v->post_date, $v->post_title );
}

[emulsion_relate_posts]