We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50719
    • 5 Posts
    Hello,
    I'm using getResources for search.
    I'm trying do that:
    'where' => '{"isfolder:=":0,"AND:hidemenu:=":0,"AND:published:=":1,"pagetitle:LIKE":"%iphone%", "AND:pagetitle:LIKE":"%5%"}',
    It's working. But when I adding something more, like
    'where' => '{"isfolder:=":0,"AND:hidemenu:=":0,"AND:published:=":1,"pagetitle:LIKE":"%iphone%", "AND:pagetitle:LIKE":"%5%", "AND:pagetitle:LIKE":"%black%"}',
    In debug I see that he didnt see first AND:pagetitle:, only last.
    How could I fix it?
    I need smth like
    SELECT * FROM -_- WHERE pagetitle LIKE %ipnone% AND pagetitle LIKE %5% AND pagetitle LIKE %black%
    and so on.
    Maby I need to change getResources for smth else?

    This question has been answered by BobRay. See the first response.

      • 47401
      • 295 Posts
      HI

      You may find this article helpful
      https://rtfm.modx.com/xpdo/2.x/class-reference/xpdoquery/xpdoquery.where

      the &where clause in the getResources needs to be added in the form of an json array.
      • discuss.answer
        • 3749
        • 24,544 Posts
        You don't need the ANDs, since that's the default. This may do it:

        &where=`{"isfolder":0,"hidemenu":0,"published":1,"pagetitle:LIKE":"%iphone%","pagetitle:LIKE":"%5%","pagetitle:LIKE":"%black%"}`


        If that doesn't work (and I don't think it will), it's because three of the array keys are the same. I think this will solve that:

        &where = `{"isfolder":0,"hidemenu":0,"published":1,"0":{"AND:pagetitle:LIKE":"%iphone%"},"1":{"AND:pagetitle:LIKE":"%5%"},"2":{"AND:pagetitle:LIKE":"%black%"}}`


        [ed. note: BobRay last edited this post 10 years, 11 months ago.]
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 50719
          • 5 Posts
          Quote from: BobRay at Oct 26, 2015, 02:03 PM
          You don't need the ANDs, since that's the default. This may do it:

          &where=`{"isfolder":0,"hidemenu":0,"published":1,"pagetitle:LIKE":"%iphone%","pagetitle:LIKE":"%5%","pagetitle:LIKE":"%black%"}`


          You may run into trouble because three of the array keys are the same, but I don't think so.

          I did it earlier. Problem is when keys the same - it saw only last. So it is the problem. How could I do same keys for where query? Without XPDO ?
            • 3749
            • 24,544 Posts
            See my corrected answer above.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 50719
              • 5 Posts
              Quote from: BobRay at Oct 26, 2015, 02:11 PM
              See my corrected answer above.
              Thanks!!
                • 3749
                • 24,544 Posts
                BTW, how I often do these is with a utility snippet (actually, I run them in my code editor) like this:

                $x = array(
                    'isfolder' => 0,
                    'hidemenu' => 0,
                    'published' => 1,
                    array('AND:pagetitle:LIKE' => '%iphone%'),
                    array('AND:pagetitle:LIKE' => '%5%'),
                    array('AND:pagetitle:LIKE' => '%black%'),
                );
                
                echo json_encode($x);


                It's easier for me than trying to write the raw JSON.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting