getResources &tvFilters articlestags with mutiple tags

@Jako - not heard of Collections before - Will take a look at that.

Thanks for the explanations. Shame we couldnt get it to work - I’ve started looking at Tagger extra which seems to work a lot better than the standard tags TV option in MODx - however it does not appear on resources that are created within an Articles blog…

Did you mean: Articles ?

If you decide to go the “scorched earth” route, here is a great tutorial for setting up a blog using Collections (instead of Articles) with Tagger (instead of a tag tv). I’ve set up three blog sites to date using this as the base and it works great.
From what I can tell the Articles extra has a lot of issues and probably is not your best option these days for designing a blog site in MODX.

Changing away from Articles is not really an option as the blog area of the site is huge (site is a good few years old, so used Articles at the time as it was the current blogging tool for MODx) - would mean a massive rebuild job. Is there no way either that tagger can work with articles to allow the tag fields to appear, or a way to get &tvFilters to accept a comma seperated list of multiple values?

It looks like both Articles and Tagger try to override/extend MODx.panel.Resource and they seem to interfere with each other.

You could try this:

[[!pdoResources?
    ...
    &tvFilters=`articlestags===tag1||articlestags==tag1,%||articlestags==%,tag1,%||articlestags==%,tag1`
    &tvFiltersAndDelimiter=`#`
]]

This searches for exact matches, the tag at the start of the string followed by a comma, the tag between commas and the tag at the end of the string after a comma.

Make sure to set the and delimiter (&tvFiltersAndDelimiter) to a different value, so that the character , in &tvFilters is not interpreted as an AND.

1 Like

I think this might have sorted it! Will do some tests this evening - thank you so much!

I can confirm this indeed seems to work! What a result - well done @halftrainedharry - hugely appreciate your time looking into this and solving the problem. Worth documenting this I would think as I am sure I am not the only one to have this issue!

Can you think of a reason why the addition of the code below would prevent the TPL that fetches a TV value from working???

[[!pdoResources? ... &tvFilters=articlestags===tag1||articlestags==tag1,%||articlestags==%,tag1,%||articlestags==%,tag1 &tvFiltersAndDelimiter=# ]]

The tpl i use as a chunk on the pdoResources call has a few TVs [[+example]] included to display the contents of TVs on the resource - but they dont work and return nothing when I include the code above in the pdoresources call… its odd… I remove the code above and the TV values are retrurned… ???

Any ideas?

I’m not sure I understand your problem correctly.

Are you saying, that when you call pdoResources without the &tvFilters property, you can output TV values in the chunk “myTplChunk” (with the tag [[+example]]),

[[!pdoResources?
    ...
    &includeTVs=`example`
    &tvPrefix=``
    &tpl=`myTplChunk`
]]

but when you add the properties &tvFilters and &tvFiltersAndDelimiter this doesn’t work anymore?


Maybe try using an empty value for the property &tpl. This should output all the placeholders that are available in the chunk.

Or try adding the property &showLog=`1` and then analyze the SQL query.

So my pdoresources call is:

[[pdoPage?
&elementClass=`modSnippet`
&element=`pdoResources`
&parents=`20,32,305`
&limit=`12`
&includeTVs=`1`
&processTVs=`1`
&includeContent=`1`
&tpl=`BlogAndNewsArticle_forFeeds_Tpl`
&tvPrefix=``
&sortby=`{"publishedon":"DESC"}`
&showHidden=`1`
&pageNavVar=`Both.nav`
&pageLimit=`1000`
&maxLimit=`1000`
&includeTVList=`NewsAndBlogArticle_isFeatured,BlogAndNewsArticleSource,BlogAndNewsSummaryImageClass,BlogAndNewsSummaryImage,BlogAuthorName,EVENTINFO_City,EVENTINFO_Country,EVENTINFO_StartDate,EVENTINFO_EndDate,EVENTINFO_ShortDescription,EVENTINFO_BoothNumber,BlogAndNewsArticleSource`
&tvFilters=`articlestags===tag1||articlestags==tag1,%||articlestags==%,tag1,%||articlestags==%,tag1
||
articlestags===tag2||articlestags==tag2,%||articlestags==%,tag2,%||articlestags==%,tag2`
&tvFiltersAndDelimiter=`#`
&showLog=`1`
]]

And the code on the BlogAndNewsArticle_forFeeds_Tpl is:

<div class="BlogAndNewsArticleTplWrapper [[+NewsAndBlogArticle_isFeatured]]">
<h3><a href="[[~[[+id]]]]" [[+link_attributes]] title="[[+pagetitle]]">[[+pagetitle]]</a></h3>   
<p class="_2016datestamp"><strong>[[+publishedon:date=`%B %d, %Y`]]</strong>
by <strong> [[*BlogAuthorName]]</strong></p>
<p class="newsItem">[[+introtext:ellipsis=`250`:strip_tags=`<br/>`]]</p>

<h5>BlogAndNewsArticleSource: [[+BlogAndNewsArticleSource]]</h5>

</div>

The value of the TV BlogAndNewsArticleSource is empty - even though it has a value on the resources being returned.

Log output is:

0.0000911: pdoTools loaded
0.0000229: xPDO query object created
0.0000701: Added TVs filters
0.0005088: Included list of tvs: articlestags
0.0001628: leftJoined modTemplateVarResource as TVarticlestags
0.0002089: Added selection of modResource: SQL_CALC_FOUND_ROWS `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `link_attributes`, `published`, `pub_date`, `unpub_date`, `parent`, `isfolder`, `introtext`, `content`, `richtext`, `template`, `menuindex`, `searchable`, `cacheable`, `createdby`, `createdon`, `editedby`, `editedon`, `deleted`, `deletedon`, `deletedby`, `publishedon`, `publishedby`, `menutitle`, `donthit`, `privateweb`, `privatemgr`, `content_dispo`, `hidemenu`, `class_key`, `context_key`, `content_type`, `uri`, `uri_override`, `hide_children_in_tree`, `show_in_tree`, `properties`
0.0000081: Added selection of modTemplateVarResource: IFNULL(`value`, '') AS `articlestags`
0.0000470: Replaced TV conditions
0.0008779: Processed additional conditions
0.0011489: Added where condition: 0=((`TVarticlestags`.`value` = 'tag1') OR (`TVarticlestags`.`value` LIKE 'tag1,%') OR (`TVarticlestags`.`value` LIKE '%,tag1,%') OR (`TVarticlestags`.`value` LIKE '%,tag1') OR (`TVarticlestags`.`value` = 'tag2') OR (`TVarticlestags`.`value` LIKE 'tag2,%') OR (`TVarticlestags`.`value` LIKE '%,tag2,%') OR (`TVarticlestags`.`value` LIKE '%,tag2')), modResource.parent:IN(20,32,305,27,127,131,134,136,145,151,126,155,157,158,159,166,167,180,186,189,190,191,308,195,309,196,310,198,311,199,312,200,313,314,317,353,361,367,377,382,384,386,387,392,401,407,410,417,419,421,422,423,428,430,433,434,436,437,438,440,443,444,446,448,449,450,451,457,458,463,464,471,473,477,478,480,481,482,484,492,576,578,580,581,583,596,591,594,599,601,602,604,605,609,610,611,615,617,619,620,623,625,627,631,634,632,637,649,647,653,658,661,663,665,670,668,672,673,674,675,676,681,682,683,684,686,690,692,693,699,696,704,707,708,714,717,725,719,722,726,824,811,827,833,829,834,838,842,846,852,850,853,854,857,862,861,864,869,870,872,875,879,877,884,137,140,141,142,143,144,146,147,148,149,150,152,153,156,160,161,162,163,164,168,169,170,171,172,173,174,185,187,192,318,193,319,194,320,197,321,201,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,354,356,359,360,363,364,365,366,369,370,371,375,378,379,380,381,383,385,388,389,393,394,400,404,405,406,408,409,411,412,413,414,418,425,426,427,429,431,432,435,439,441,442,445,447,453,454,455,456,459,461,462,466,467,468,469,470,472,475,476,479,483,485,487,488,491,560,573,574,575,577,582,584,588,589,592,593,595,597,598,600,603,607,608,612,613,614,616,618,621,622,624,626,628,629,630,633,635,636,640,641,642,643,644,645,646,648,650,651,652,654,657,659,660,662,664,667,669,671,677,678,680,685,687,688,695,698,701,702,703,705,706,709,710,711,712,713,715,716,718,720,721,724,822,823,825,826,828,831,832,839,840,841,843,844,845,847,848,849,851,855,856,858,859,863,865,866,867,868,871,873,874,876,878,880,881,882,883,886,306), modResource.published=1, modResource.deleted=0
0.0000041: Replaced TV conditions
0.0001328: Sorted by modResource.publishedon, DESC
0.0000019: Limited to 12, offset 0
0.0002749: SQL prepared "SELECT SQL_CALC_FOUND_ROWS `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`link_attributes`, `modResource`.`published`, `modResource`.`pub_date`, `modResource`.`unpub_date`, `modResource`.`parent`, `modResource`.`isfolder`, `modResource`.`introtext`, `modResource`.`content`, `modResource`.`richtext`, `modResource`.`template`, `modResource`.`menuindex`, `modResource`.`searchable`, `modResource`.`cacheable`, `modResource`.`createdby`, `modResource`.`createdon`, `modResource`.`editedby`, `modResource`.`editedon`, `modResource`.`deleted`, `modResource`.`deletedon`, `modResource`.`deletedby`, `modResource`.`publishedon`, `modResource`.`publishedby`, `modResource`.`menutitle`, `modResource`.`donthit`, `modResource`.`privateweb`, `modResource`.`privatemgr`, `modResource`.`content_dispo`, `modResource`.`hidemenu`, `modResource`.`class_key`, `modResource`.`context_key`, `modResource`.`content_type`, `modResource`.`uri`, `modResource`.`uri_override`, `modResource`.`hide_children_in_tree`, `modResource`.`show_in_tree`, `modResource`.`properties`, IFNULL(`TVarticlestags`.`value`, '') AS `articlestags` FROM `modx_site_content` AS `modResource` LEFT JOIN `modx_site_tmplvar_contentvalues` `TVarticlestags` ON `TVarticlestags`.`contentid` = `modResource`.`id` AND `TVarticlestags`.`tmplvarid` = 1 WHERE  ( ((`TVarticlestags`.`value` = 'tag1') OR (`TVarticlestags`.`value` LIKE 'tag1,%') OR (`TVarticlestags`.`value` LIKE '%,tag1,%') OR (`TVarticlestags`.`value` LIKE '%,tag1') OR (`TVarticlestags`.`value` = 'tag2') OR (`TVarticlestags`.`value` LIKE 'tag2,%') OR (`TVarticlestags`.`value` LIKE '%,tag2,%') OR (`TVarticlestags`.`value` LIKE '%,tag2')) AND `modResource`.`parent` IN (20,32,305,27,127,131,134,136,145,151,126,155,157,158,159,166,167,180,186,189,190,191,308,195,309,196,310,198,311,199,312,200,313,314,317,353,361,367,377,382,384,386,387,392,401,407,410,417,419,421,422,423,428,430,433,434,436,437,438,440,443,444,446,448,449,450,451,457,458,463,464,471,473,477,478,480,481,482,484,492,576,578,580,581,583,596,591,594,599,601,602,604,605,609,610,611,615,617,619,620,623,625,627,631,634,632,637,649,647,653,658,661,663,665,670,668,672,673,674,675,676,681,682,683,684,686,690,692,693,699,696,704,707,708,714,717,725,719,722,726,824,811,827,833,829,834,838,842,846,852,850,853,854,857,862,861,864,869,870,872,875,879,877,884,137,140,141,142,143,144,146,147,148,149,150,152,153,156,160,161,162,163,164,168,169,170,171,172,173,174,185,187,192,318,193,319,194,320,197,321,201,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,354,356,359,360,363,364,365,366,369,370,371,375,378,379,380,381,383,385,388,389,393,394,400,404,405,406,408,409,411,412,413,414,418,425,426,427,429,431,432,435,439,441,442,445,447,453,454,455,456,459,461,462,466,467,468,469,470,472,475,476,479,483,485,487,488,491,560,573,574,575,577,582,584,588,589,592,593,595,597,598,600,603,607,608,612,613,614,616,618,621,622,624,626,628,629,630,633,635,636,640,641,642,643,644,645,646,648,650,651,652,654,657,659,660,662,664,667,669,671,677,678,680,685,687,688,695,698,701,702,703,705,706,709,710,711,712,713,715,716,718,720,721,724,822,823,825,826,828,831,832,839,840,841,843,844,845,847,848,849,851,855,856,858,859,863,865,866,867,868,871,873,874,876,878,880,881,882,883,886,306) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 )  ORDER BY modResource.publishedon DESC LIMIT 12 "
0.0042012: SQL executed
0.0001280: Total rows: 6
0.0000811: Rows fetched
0.0003960: Could not process or prepare TV "1"
0.0022209: Could not process or prepare TV "1"
0.0012820: Could not process or prepare TV "1"
0.0010681: Could not process or prepare TV "1"
0.0011380: Could not process or prepare TV "1"
0.0010259: Could not process or prepare TV "1"
0.0077939: Prepared and processed TVs
0.0008850: Loaded "modChunk" with name "BlogAndNewsArticle_forFeeds_Tpl"
0.0292060: Returning processed chunks
0.0442250: Total time
6 291 456: Memory usage

The &includeTVs property in pdoResources is a “comma-separated list of Template Variable values”.

&includeTVs=`1` is only correct for getResources.
For pdoResources use &includeTVs=`BlogAndNewsArticleSource` .

Thanks - but doesnt change antyhing - still value does not appear in the pdoresources results.

The issue is 100% due to the tvFilters parameter - If i remove it the TV value renders as it should.

A blank value for the tvFilters results in the TV appearing - e.g. tvFilters=`` - but as soon as the required values are added to that parameter - the TV fails to appear.

It seems to be that for some reason the TV wants to pull data from the resource on which the pdoresources call is on and put pulling the value of the TV from the resource pdoresources is displaying…

Try calling pdoPage uncached (with the !). Paging snippet should always be uncached.

[[!pdoPage?
    ...
]]

In your chunk replace [[*BlogAuthorName]] with [[+BlogAuthorName]].

Afraid I’ve tried all that already - doesnt make any difference.

UPDATE… think i’ve resolved it… just removed

includeTVs=`1`
&includeTVList=`NewsAndBlogArticle_isFeatured,BlogAndNewsArticleSource,BlogAndNewsSummaryImageClass,BlogAndNewsSummaryImage,BlogAuthorName,EVENTINFO_City,EVENTINFO_Country,EVENTINFO_StartDate,EVENTINFO_EndDate,EVENTINFO_ShortDescription,EVENTINFO_BoothNumber,BlogAndNewsArticleSource`

And changed [[*BlogAuthorName]] back to [[+BlogAuthorName]] and its working!

Because I was struggling with this issue and couldn’t get the above solution to work for me, I’m posting a solution that did… Listing MODX Articles with at least one common tag - Stack Overflow

@chrisandy The problem with the solution you linked to is, that it does not match the whole tag.
If for example you want to filter by the tag “car”, it will also display resources with tags like “scarf”, “postcard” or “healthcare” (where the character string “car” is part of the tag).

Understood but I couldn’t find a better solution and it may just help somebody