Thanks for an interesting question and for including the source text of your shortcodes, which are very creative. I want to make sure I understand your goal and how the shortcodes relate to it.
Your shortcodes include these parameters:
mla_search_fields=title s="{+page_title+}" sentence=true
That means you want to select all the items where the item Title field contains the Title value of the page/post in which the [mla_gallery]
shortcode appears; is that right? Is this in addition to the query on tag values you are asking about?
Your second shortcode has a bit of single/double quote confusion that generates a parse error. You have a tax_query
parameter delimited by double quotes. Most of the elements within this parameter are delimited by single quotes, but you also have 'terms'=>"{+similar+}",
, which has double quotes. This causes an “invalid tax_query” error.
That said, let us move on to your primary question.You want to select items that have both of two post_tag
values; “primary” and a custom field value. You have specified a “simple taxonomy query” tag="primary"
for the first value and a tax_query
for the second value. That will work – the two queries are joined by AND, which is what you want.
You wrote “the value in the custom field named “similar-work”“, but you do not say where the custom field is defined. Is it in the post/page that contains the [mla_gallery]
or is it in the Media Library items? I assume it is defined in the post/page containing the [mla_gallery]
because defining it in the items makes no sense. Is that right?
It looks like the 'terms'=>'{+similar+}',
parameter is where the custom field value should go. I regret that “similar
” won’t work because it is not one of the standard MLA data sources. The 'terms'=>'{+custom:similar+}',
alternative won’t work either, because the custom:
prefix looks in the Media Library items and these are not known when the database query is constructed. If you want to access a custom field value in the page/post that contains the [mla_gallery]
shortode you are stuck; there is no syntax in the current MLA version that supports this feature.
The answer is to construct some PHP code for your theme’s functions.php
file or a small custom plugin that can intercept the [mla_gallery]
parameters and fix the tax_query
parameter along the lines you need. If that works for you, and if I have understood your question correctly, let me know and I will work out some code.
Thanks for any additional details you can provide.