• Resolved jhdean

    (@jhdean)


    Hello David,

    I am trying to make a version of the following shortcode that builds a gallery with both tag=”primary” and
    tag=(the value in the custom field named “similar-work”

    [mla_gallery columns=1 mla_search_fields=title s="{+page_title+}" sentence=true tag="primary" link="none" size=large mla_caption=" " mla_markup="detail-page" my_gallery_title="{+page_title+}"]

    The following was my failed attempt:
    <code>[mla_gallery columns=1 mla_search_fields=title s="{+page_title+}" sentence=true tag="primary" tax_query="array(array('taxonomy'=>'post_tag','field'=>'slug','terms'=>"{+similar+}",'operator'=>'IN'),'relation'=>'AND')" link="none" size=large mla_caption=" " mla_markup="detail-page" my_gallery_title="Similar Work"" ]</code>

    Any help you can offer would be great.
    Thanks,
    Jeff

    https://www.ads-software.com/plugins/media-library-assistant/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author David Lingren

    (@dglingren)

    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.

    Thread Starter jhdean

    (@jhdean)

    The custom field is defined in the Media Library Assistant settings. It is mapped from an IPTC field on import so I can enter a keyword for the image beforehand that can be used in the shortcode for the gallery.

    It looks like the ‘terms’=>'{+similar+}’, parameter is where the custom field value should go.

    I think that should have been “similar-work”. It was meant to produce the value in the custom field.

    <code>[mla_gallery columns=1 mla_search_fields=title s="{+page_title+}" sentence=true tag="primary" link="none" tax_query="array(array('taxonomy'=>'post_tag','field'=>'slug','terms'=>'similar-work','operator'=>'IN'),'relation'=>'AND')"size=large mla_caption=" " ]</code>

    This version has no error but doesn’t have any results. With my clarification about the custom field definition, is it possible to do this within MLA itself?

    If not, the custom PHP would be great. Thank you as always for offering to help with it.

    Thanks,
    Jeff

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the additional information. I regret that I am still a bit confused about your application. You wrote:

    The custom field is defined in the Media Library Assistant settings. It is mapped from an IPTC field on import so I can enter a keyword for the image beforehand that can be used in the shortcode for the gallery.

    If the custom field is defined in the Media Library items there is no way to use item-specific values as a query parameter in the [mla_gallery] shortcode; until the query is finished there are no items. As I wrote earlier,

    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.

    You could use an IPTC/EXIF mapping rule to map the IPTC value into the Att. Tag taxonomy and then use a tax_query to filter by the value. You can also define a Custom Field Query to use the field you have already set up; something like:

    <code>[mla_gallery columns=1 mla_search_fields=title s="{+page_title+}" sentence=true tag="primary" link="none" meta_key="similar-work" meta_value="xxxx" size=large mla_caption="{+template:({+empty+})+}" ]</code>

    where “xxxx” is the keyword you’ve mapped into the custom field. Does that make sense?

    By the way, if you want to suppress the caption you should use this syntax: mla_caption="{+template:({+empty+})+}".

    Thread Starter jhdean

    (@jhdean)

    Thanks David,

    It seems that the only solution is manually entering the search value in each shortcode instance. I understand now that the shortcode would have to be evaluated twice to lookup the search term and then use it for the search.

    Jeff

    Plugin Author David Lingren

    (@dglingren)

    Jeff,

    I think your understanding is correct; I can’t think of a way to more fully automate the flow.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the combinations of search, term and custom field parameters in [mla_gallery].

    Of course, if you come up with a better solution it would be great to share it as well. Good luck with your application.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search based on value in custom field’ is closed to new replies.