We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27733
    • 99 Posts
    Greetings. I’m looking to retrieve a snippet’s id based on its name. Would you use a query ala

    $c = $modx->newQuery('modSnippet');
    $c->where(array(
      'name' => 'snippetname'
    ));
    $resource = $modx->getOne('modSnippet',$c);
    $id = $resource->get('id');


    Or, is there an easier way to do this?
      ------
      Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.
      • 3749
      • 24,544 Posts
      Quote from: smg6511 at Mar 31, 2011, 01:46 PM

      Greetings. I’m looking to retrieve a snippet’s id based on its name. Would you use a query ala

      $c = $modx->newQuery('modSnippet');
      $c->where(array(
        'name' => 'snippetname'
      ));
      $resource = $modx->getOne('modSnippet',$c);
      $id = $resource->get('id');


      Or, is there an easier way to do this?



      $snip = $modx->getObject($modSnippet, array('name'=> $name));
      $id = $snip->get('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
        • 27733
        • 99 Posts
        Thanks a bunch, Bob. I figured there was a shorter path to what I wanted!
          ------
          Server: *nix, ModX Evo 1.0.4, Apache 2.x, PHP 5.x, Mysql 5.x.