TangibleInc / template-system

A template system for WordPress with content type loops and conditions
https://docs.loopsandlogic.com/reference/template-system/
6 stars 2 forks source link

Taxonomy term loop's `post` attribute does not accept list variables #79

Closed BenTangible closed 7 months ago

BenTangible commented 7 months ago

In my experience, any attribute that accepts array data is compatible with both a manually entered comma-separated list as well as a dynamic reference to a list variable. However, I've just noticed that the post query parameter in the taxonomy term loop doesn't seem to work this way and only accepts a comma-separated list. Here's an example of a template that passes the same data to the post parameter, first manually and then as a list variable. I've added the resulting output below.

<List post_ids>
  <Item>21</Item>
  <Item>18</Item>
  <Item>20</Item>
  <Item>15</Item>
</List>

<p>Contents of the list: <Get list=post_ids /></p>

<h2>Loop using manual list of post IDs</h2>
<ul>
  <Loop type=taxonomy_term taxonomy=category post="21,18,20,15" orderby=term_order order=asc>
    <li><Field title /></li>
  </Loop>
</ul>

<h2>Loop using the saved list of post IDs</h2>
<ul>
  <Loop type=taxonomy_term taxonomy=category post="{Get list=post_ids}" orderby=term_order order=asc>
    <li><Field title /></li>
  </Loop>
</ul>

Result:

image

eliot-akira commented 7 months ago

any attribute that accepts array data is compatible with both a manually entered comma-separated list as well as a dynamic reference to a list variable

This is true specifically for loop query parameters which are defined in the loop type definition as having the type array.

The base loop class, from which all loop types inherit, has a function which converts given arguments (tag attributes) into query parameters based on their definitions. When a parameter accepts an array, the value is parsed as a comma-separated list or JSON array (from list variable or written by hand).


It turns out the bug you found was specific to the Taxonomy Term loop's post attribute, whose value was getting turned into a list before this common conversion step.


Notably, the conversion doesn't happen with tag attributes that are not loop query parameters. Such attributes are processed by individual tag functions. To make them all support JSON array, these tags should use a common function to parse such values. A quick search shows about a dozen places where comma-separated lists are handled.

eliot-akira commented 7 months ago