We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28508
    • 73 Posts
    Hello,

    I’d like to show not all, but just some selected resources in archivist.
    In my opinion it doesn’t make sense to show a contact-page there, for example.
    I thought about doing this by modifiying the SQL-Query in the snippet in order to filter by a TV, but unfortunately it didn’t work.

    $c = $modx->newQuery('modResource');
    $fields = $modx->getSelectColumns('modResource','','',array('modResource.id',$sortBy));
    $c->select($fields);
    $c->select(array(
        'FROM_UNIXTIME(`'.$sortBy.'`,"'.$sqlDateFormat.'") AS `date`',
        'FROM_UNIXTIME(`'.$sortBy.'`,"'.$sqlDateFormat.'") AS `date`',
        'FROM_UNIXTIME(`'.$sortBy.'`,"%D") AS `day_formatted`',
        'COUNT(*) AS `count`',
    ));
    
    // join tv table, using tv 18 
    $c->leftJoin('modTemplateVarResource', 'Tpl', array(
     'modResource.id' => 'Tpl.contentid',
     'AND:Tpl.contentid:=' => '18'
     ));
    
    // only get entries where tv 18 is not set (so value is null)
    $c->where(array(
     'modResource.published' => true,
     'AND:modResource.deleted:=' => false,
     'AND:modResource.hidemenu:=' => '0',
     'AND:Tpl.value:=' => null
     ));
    
    
    $resources = $modx->getCollection('modResource', $c);


    Could anyone give me a small hint what might be wrong with my code?

    This SQL-Query gives me the right IDs:
     SELECT c.id FROM modx_site_content c LEFT JOIN modx_site_tmplvar_contentvalues t
     ON (c.id=t.contentid AND t.tmplvarid=18) WHERE 
     c.published=true AND c.deleted=false AND c.hidemenu='0' and t.value IS NULL;



    Thank you,
    stetus