2

Why would this not work as a Views PHP filter criteria?

if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {
  $node = node_load(arg(1));
  $a1 = format_date($node->created, 'custom', 'm/d/Y');
  $a2 = date('m/d/Y',strtotime('-2 months',strtotime($a1)));  
  $a3 = format_date($row->created, 'custom', 'm/d/Y');

  $b1 = new DateTime($a1);
  $b2 = new DateTime($a2);
  $b3 = new DateTime($a3);

  if ($b3 < $b2) {
    return TRUE;
  }
}

The code should remove rows that are older than the current node except it doesn't?!

1

It will remove the rows, when you return FALSE:

if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {
  $node = node_load(arg(1));
  $a1 = format_date($node->created, 'custom', 'm/d/Y');
  $a2 = date('m/d/Y',strtotime('-2 months',strtotime($a1)));  
  $a3 = format_date($row->created, 'custom', 'm/d/Y');

  $b1 = new DateTime($a1);
  $b2 = new DateTime($a2);
  $b3 = new DateTime($a3);

  if ($b3 >= $b2 && $b3 <= $b1) {
    return FALSE;
  }
  else {
    return TRUE;
  }
}
| improve this answer | |
  • Thanks. Just swapped TRUE/FALSE since TRUE hides rows but as per your answer you do need the else statement – Stephen Wilson Jun 5 '13 at 9:18

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.