We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38142
    • 91 Posts
    Problem: I have two contexts, both with a list of child resources that have identical pagetitles between the two contexts, and I need to be able to get a resource while specifying which context to look in. When I exclude the context line from the criteria below, the snippet works; when I include the context line, it breaks. So how do you narrow the search down to a specific context?

    $context = $modx->context->key;
    
    $name = 'modResource';
    $criteria = array(
        'published' => 1,
        'pagetitle' => $pagetitle,
        'context' => $context
    );
    $resource = $modx->getObject($name,$criteria);
    $docid = $resource->get('id');

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

    • discuss.answer
      • 3749
      • 24,544 Posts
      Try this:
      'context_key' => $context
        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
        • 38142
        • 91 Posts
        Quote from: BobRay at Jan 08, 2018, 11:01 AM
        Try this:
        'context_key' => $context

        BINGO!!

        Once again, Bob, you have been extremely helpful and have saved someone's bacon, as the Anglo-Saxons used to say.