MODX Community

Can you edit taglister to filter by TV, or can you add a tv into the array for getChildIds

I’m using a copy of the taglister snippet to take tags articlestags in one context and display them in another. It’s working just fine after I added an array to getChildId to give context access.

BUT I have a tv on each article that defines them into a category, lets say either apples and oranges. I want taglister to only display tags from articles that a tv value of oranges. I don’t get into the deeper levels of modx coding, but my initial instinct was this:

$kids = $modx->getChildIds(65,10,array(‘context’ => ‘blog’ ,’ tv.BLOG-category’ => ‘oranges’ ));

But that didn’t work. Any suggestions?

The only “option” getChildIds() responds to is context, so adding criteria definitely won’t work.

I think you’re going to have to do something more complicated. This is a slow way to do it, but it may give you the concept. It should return a comma-separated list of the IDs of the resources you want:

$tvId = 12;
$kids = $modx->getChildIds(65,10,array('context' => 'blog');
$docs = array();
$value = 'orange';

foreach($kids as $kid) {
     $id = $kid->get('id');
     $c= array(
         'contentid' => $kid->get('id'),
          'tmplvarid' => $tvId,
          'value' => $value,
     );
     $doc = $modx->getObject('modTemplateVarResource', $c);
     if ($doc) {
         $docs[] = $id;
      }

}

return implode(',', $docs);

A much faster way would be with a single query using a join of the modResource and modTemplateVarResource tables looking for resources with an id IN the $kids array and with a TVR value of orange, but I’m too tired to work it out right now and it’s not worth attempting until you make sure the method above works and can be integrated with taglister.

Using Tagger for Tags and Categories might be the better option