We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    Hi, I'm trying to get a resource in a snippet based on a TV value ... below the $query works & is what I am trying to replicate with the xPDO syntax - though I'm just not sure how to do it ~or~ if the TV values are already a part of the modResource collection I have already pulled... [if so, how can I access the TV values?]

    $query = "SELECT tvs.*, tvv.*, sc.*
    FROM modx_site_tmplvar_contentvalues tvv 
    left join modx_site_tmplvars tvs
    on tvs.id = tvv.tmplvarid
    left join modx_site_content sc on sc.id = tvv.contentid
    where tvs.name = 'DoorsOpen'
    and tvv.value like '2012-06-20%';";
    
    
    $today = date('Y-m-d');
    
    $crit = array(
        'published' => 1,
        'parent' => 24
    );
    
    
    $documents = $modx->getCollection('modResource', array('modTemplateVar'=>array()), $crit);
    
    
    foreach($documents as $document){
      
    echo  $document->get('pagetitle');
    
    }
    


    any help?
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 9102 ☆ A M B ☆
      • 318 Posts
      Start by getting a collection of modTemplateVarResource and then get the associated resources. Something like:
      $tvid = $modx->getObject('modTemplateVar', array('name' => 'DoorsOpen'))->get('id');
      $query = $modx->newQuery('modTemplateVarResource');
      $query->where(array(
          'tmplvarid' => $tvid,
          'value:LIKE' => '2012-06-20%'
      ));
      $tvvals = $modx->getCollection('modTemplateVarResource', $query);
      foreach ($tvvals as $tvval) {
          $document=$tvval->getOne('Resource');
          echo  $document->get('pagetitle');
      }
      


      Edit to add: you'll want to add a condition inside the foreach loop to pick out only the resources with the properties you want. [ed. note: esnyder last edited this post 14 years, 4 months ago.]