Use post__in and post__not_in together?

post__in and post__not_in are mutually exclusive.

Note: you cannot combine post__in and post__not_in in the same query.

http://codex.wordpress.org/Class_Reference/WP_Query

As your question is written, the solution you reject– that of using array_diff— is the obvious answer.

If it is true that that solution won’t work you will need a filter on posts_where (probably) that will provide the query logic you need. As you have not explained “the reality [that] is more complicated than this question” it is really not possible to offer a guess at what that logic might be.

But here is an example of a posts_where filter:

function smbd_cats_by_days ($where="") {
    // global $days_limit; // if a variable
    // $days_limit = DAYS_LIMIT; // if a constant
    // $days_limit = get_option('days_limit',100);
    // you have to uncomment one of the above, 
    // depending on your choice of mechanisms
    $where .= " AND post_date < '" . date('y-m-d', strtotime("-{$days_limit} days")) . "'";
    return $where;
}
add_filter('posts_where', 'smbd_cats_by_days');

Based on the edit to the question and on this statement of intent:

I’m trying to only show posts that a user hasn’t seen…

Write the PHP to create an array of posts that the user has seen and exclude them with post__not_in. Your attempt to shove everything into the query is only complicating things.

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.

By the time your write the filters and or SQL to include everything in the query it will not be more “readable” and it is questionable whether it would be more readable in the first place. You are trying to do this the hard way. WP_Query is not capable of complex logic and complex logic in SQl is hard to write and hard the read even on a good day.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)