contact
is a matrix with 3 columns: office
, direct_phone
, direct_fax
direct_phone
& direct_fax
are text fields
office
is a single select playa field
office_phone
is a text input on the offices channel
SELECT md.entry_id, # Get the {entry_id} from matrix_data,
cd.field_id_56, # {office_phone} from channel_data and
md.col_id_48 # {direct_phone} from matrix_data
FROM exp_matrix_data AS md #
LEFT JOIN exp_playa_relationships AS pr #
ON md.entry_id = pr.parent_entry_id #
LEFT JOIN exp_channel_data AS cd #
ON pr.child_entry_id = cd.entry_id #
WHERE md.field_id = 123 # where the matrix field is {office}
AND md.row_order = 1 # and only grab the first row.
GROUP BY md.entry_id # This prevents extra columns from playa_relationships.
ORDER BY md.entry_id ASC # Order by {entry_id}
I check if the person has a direct_phone
and, if so, store it in Stash. If not, store the office_phone
from the office they are in.
I am using cache="no"
so the Stash vars aren't written to and read from the DB.
This method reduced the number of queries on this page from ~800 down to ~40 per (uncached) page load.
If I remember Low's Parse Order presentation well, modules {exp:tags} are parsed in the order they are in the template. If nested the parser deals with them from the root of the document inwards