We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38878
    • 255 Posts
    Can anyone see anything wrong with this query syntax assuming vars are defined?

        $user = $modx->getUser();
        $user_id = $user->get('id');
        $c->where(array(
            'title:LIKE' => '%'.$term.'%',
            'AND:deleted:=' => '0',
            'AND:createdby:=' => $user_id,
        ));


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

      • 3749
      • 24,544 Posts
      Try this ('AND' is the default):

      $user_id = $modx->user->get('id');
      $c->where(array(
          'title:LIKE' => '%'.$term.'%',
          'deleted' => 0,
          'createdby' => $user_id,
      ));
        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
      • What are you trying to get? A resource created by the current user? For one thing, Resources don't have a "title" field, they have "pagetitle" field.

        Note: A common mistake when getting a resource is to use 'name' or 'title' instead of 'pagetitle'. Resources do not have a 'name' or 'title' field even though the caption on the Create/Edit Resource panel for the pagetitle field is 'title.'
        http://bobsguides.com/revolution-objects.html









          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
        • discuss.answer
          • 38878
          • 255 Posts
          Quote from: BobRay at Nov 28, 2015, 08:03 PM
          Try this ('AND' is the default):

          $user_id = $modx->user->get('id');
          $c->where(array(
              'title:LIKE' => '%'.$term.'%',
              'deleted' => 0,
              'createdby' => $user_id,
          ));

          Thanks Bob. A little confusing when to use those extra colons and whatnots. FYI, its a db object, not a standard resource, thus the title property. I'm getting a 404 error hitting the snittet via ajax and just trying to shake it out.
          • If it's an AJAX call, then a 404 error usually means that the URL to the resource containing the the snippet is not correct. Does having the snippet simply return something like "Hello" work as expected?
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 38878
              • 255 Posts
              Quote from: sottwell at Nov 29, 2015, 04:48 AM
              If it's an AJAX call, then a 404 error usually means that the URL to the resource containing the the snippet is not correct. Does having the snippet simply return something like "Hello" work as expected?

              Yes, the snippet call is correct. When I load the resource directly in the browser without a query string I get the expected response. But when I add a query string I get a 404. I figured out that the server didn't like a querystring key of "q" for the search term. Once I changed the keyname to something else everything worked. Seems kinda random, but there it is.

              Anyone using select2 jquery addon on the front-end should be aware of this little oddity.

              Thanks for your help.
              • That's because "q" is what MODX uses for its rewrite. domain.com/index.php?q=alias
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 38878
                  • 255 Posts
                  Quote from: sottwell at Nov 29, 2015, 04:27 PM
                  That's because "q" is what MODX uses for its rewrite. domain.com/index.php?q=alias

                  Well there you go;) Makes sense now. Thanks Susan.