I'm trying to only show posts that a user hasn't seen, like this:
$exclude = array(1,2,3); $include = array(3,4,5); $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 30, 'post__in' => $include, 'post__not_in' => $exclude, 'orderby' => 'post__in', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array($category_names), 'operator' => 'IN' ), array( 'taxonomy' => 'category', 'field' => 'ID', 'terms' => array($category_ids), 'operator' => 'NOT IN' ) ) ); $posts = get_posts($args);
I'd expect this to return posts 4 and 5, but it returns 3, 4, and 5.
How do I set which gets preference between 'post_in' and the 'post_not_in' parameters?
I know that I could use array_diff() on the $exclude and $include variables, but the reality is more complicated than this question. I have many different arrays to compare against, and some of them are multidimensional. I'm also including and excluding certain taxonomies.
I also think it's easier for others to read if it's a WP_Query or $wpdb call, rather than lines and lines of PHP to end up with a query parameter.
Also, if array_diff equal an empty array, then the query actually returns posts, not nothing.
So perhaps the best way is a $wpdb call, or a way to use WP_Query's meta_query on the post ID field?