Support

Account

Home Forums Add-ons Gallery Field Gallery field – query filtering by taxonomies

Solving

Gallery field – query filtering by taxonomies

    • Nano09

    • December 17, 2018 at 3:25 pm

    Hello,

    We’re doing a query on images uploaded to a Gallery field and need to filter results taking in account taxonomies attached to those images (setup in the ‘media library’).

    For example:

    1) I upload 5 images to the ACF gallery field in my post.
    2) In the ‘media library’ I add categories to each one of those 5 images (colours for example: black, blue, yellow, etc).
    3) In a query, I need to output all images in the ACF gallery field that are category ‘yellow’.

    https://www.advancedcustomfields.com/resources/gallery/
    We checked this page and found that taxonomies are not included in the results.

    Does anyone know how I can achieve this?

    Thank you very much! ๐Ÿ™‚

    • Nano09

    • December 19, 2018 at 3:44 pm

    Hey guys,

    Does anyone have any idea on how I can achieve what I am after? ๐Ÿ™‚

    Also, I saw in the changelog for the latest update (5.7.9) there is a line that says:

    * Dev – Added filter ‘acf/connect_attachment_to_post’ to prevent connecting attachments to posts.

    Does this mean that it is possible to create a query that pulls images from the media library to display on a page, keeping it connected to the post they are attached to? In this way, when you click on the image it could take you to the post they are attached to?

    Thanks!

    • Nano09

    • December 19, 2018 at 4:30 pm

    This explains what I am trying to achieve:

    ACF Gallery field

  • ACF does not support taxonomies for media files because this is not supported natively by WP. Customization needs to be done in WP to do this, either through code or by using a plugin. I’ve looked into the ACF code and there isn’t any way to filter images for a gallery by taxonomy and there isn’t any way to add taxonomies to the array of images returned.

    (I suppose that you could add a load value filter https://www.advancedcustomfields.com/resources/acf-load_value/ or maybe a format value filter https://www.advancedcustomfields.com/resources/acf-format_value/ to the gallery field to add this information to the value before it is returned, but I’m not 100% sure on how to do this.)

    I’m not exactly sure where you want to do this filtering.

    If you want to do it in the admin you’d need to build a new type of gallery field that includes filters for your custom media taxonomy https://www.advancedcustomfields.com/resources/creating-a-new-field-type/. It may also be possible to add field settings to the existing gallery field https://www.advancedcustomfields.com/resources/adding-custom-settings-fields/ and then add filters to the gallery field to alter how it works to use these settings to filter images, but I’m not even sure this is possible. The gallery field works in conjunction with the standard WP media library popup and dealing with this can be complicated if it can be done at all.

    If you want to filter them on the front end…. if it were me I’d add a filter to the gallery load value hook, or more likely I would loop though all the images that ACF returns and only show the ones that should be shown based on additional queries.

    Sorry for the long answer that probably didn’t help you, but there isn’t a simple solution to this and any solution is going to involve a lot of coding to accomplish.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.