Lost in Where

Lost in Where

nessinitsnessinits Posts: 86Questions: 27Answers: 0

Hi all,

I need a .php where clause in my serverside PHP:
'WHERE published <= ' . "'" . Now() . "' " .
'AND published IS NOT NULL ' .
'AND (closed IS NULL '.
'OR closed >= ' . "'" . Now() . "') " .
'ORDER BY published DESC ';

How should I convert this to ->where() ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Its all about using anonymous functions to get the grouping:

    ->where( function ( $q ) {
      $q->where( 'published', 'now()', '<=', false );
      $q->where( 'published', null, '!=' );
      $q->where_group( function ( $q1 ) {
        $q1->where( 'closed', 'now()', '>=', false );
        $q1->or_where( 'closed', null );
      } );
    } );
    

    Allan

This discussion has been closed.