Fabrice
10/9/2019 - 9:46 AM

wordpress loop two filter order not_in

<?php

	$args = array( 
		'post_type' 		=> 'publication',
		'posts_per_page' 	=> '-1',
		'meta_query' => array(
			'relation' => 'OR',
			array(
				'key' => 'publication_order',
				'compare' => 'EXISTS'
			)
		),
		'meta_key'			=> 'publication_order',
		'orderby'			=> 'meta_value',
		'order'				=> 'ASC'
	);
	$loop = new WP_Query($args); 
	
	$liste_sticky = [];
	while ( $loop->have_posts() ) : $loop->the_post();
		$liste_sticky[] = get_the_ID();
		get_template_part('parts/publications/loop', 'publications');
	endwhile; 
	wp_reset_postdata(); 

	$args = array( 
		'post_type' 		=> 'publication',
		'posts_per_page' 	=> '-1',
		'post__not_in' 			=> $liste_sticky,
		'meta_key'			=> 'publication_year',
		'orderby'			=> 'meta_value',
		'order'				=> 'DESC'
	);
	$loop = new WP_Query($args); 
	
	while ( $loop->have_posts() ) : $loop->the_post();
		get_template_part('parts/publications/loop', 'publications');
	endwhile; 
	wp_reset_postdata();

?>