0

I'm trying to write a wp_query that will filter out posts with a certain tag only if they are also 1 month old. All posts older then a month without the tag are displayed and any post less then a month old is displayed.

After learning about date_query from a pervious post this was my attempt. However I found that post__not_in needs an ID, and OR relations are for meta_queries but I just want a regular query with 2 sets of possible solutions. Either A it doesn't have the tag and time doesn't matter, or b it has the tag and after a month it is no longer displayed. Alternatively is there a way I can just write SQL to do this?

$onemonth_before = date( 'Y-m-d', strtotime('-1 month'));
$args = array(
  'post__not_in' => array(
    'tag' => 'x-post',
    'date_query' => array(
      'before' = $onemonth_before,
      'inclusive' = true,
    ),
  ),
);
$query = new WP_Query( $args );
0

I think your query is wrong post__not_in only accepts array of post_id's only.

I think it should be like this.

$onemonth_before = date('Y-m-d', strtotime('-1 month'));
$args = array(
  'tag__not_in' => array(<pass tag_id here>),
  'date_query' => array(
      'before' = $onemonth_before,
      'inclusive' = true,
   ),
);
$query = new WP_Query($args);
|improve this answer|||||
  • How do I set the relation between when the tag is present and it requiring a time check though? in meta_query you can set an OR but for a regular $args it's not an option. I need something akin to doing a WHERE clause for SQL – benikens Oct 10 '17 at 22:33
  • You want set date option on tag? – BlueSuiter Oct 11 '17 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.