Is it possible to do an OR on the Where clause?

Is it possible to do an OR on the Where clause?

pzh20pzh20 Posts: 66Questions: 15Answers: 0

Question is in the Title. I need to filter record based on one or the other clauses.

Regards
Pete

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Yes absolutely. The where() method in Editor 1.4 accepts an anonymous function which gives you access to the query instance Editor is using. With that you can use its or_where() method:

    ->where( function ( $q ) {
      $q->where( 'field1', 'value1' );
      $q->or_where( 'field2', 'value2' );
    } )
    

    The API reference for this is available here.

    Allan

This discussion has been closed.