Thanks for your question. I assume when you write “programatically” you mean that you want to write some PHP code that executes an MLA query to return “all assets with a specific tag“; is that right?
There are a few ways to accomplish your goal. They use different methods to execute this MLA shortcode:
[mla_gallery post_parent=all post_mime_type=all attachment_tag=abc]
Where you can adjust the final parameter to use the taxonomy and term names/slugs to suit your application.
This shortcode returns HTML markup that displays a gallery containing the selected Media Library items. You could use the WordPress do_shortcode()
function to execute it, or you could call MLA’s MLAShortcodes::mla_gallery_shortcode()
function directly. You can find function definitions and documentation in the /media-library-assistant/includes/class-mla-shortcodes.php
file.
For programatic use, however, you probably don’t want to mess with the HTML markup. You can get an array of attachment objects, attachment ID values or ID and post_parent properties by calling the MLAShortcodes::mla_get_shortcode_attachments()
function. You can add the Return Fields Parameter in the $attr array to set return values. There are three options:
- ‘all’ – Return all fields (default).
- ‘ids’ – Return an array of post IDs.
- ‘id=>parent’ – Return an array of stdClass objects with ID and post_parent properties.
Passing anything else will return all fields (default) – an array of post objects. Here’s a code fragment you can tinker with:
$attr = array( 'post_parent' => 'all', 'post_mime_type' => 'all', 'attachment_tag'' => 'abc', 'fields' => 'all' );
$results = MLAShortcodes::mla_get_shortcode_attachments( 0, $attr );
I hope that gets you started on a solution for your application. I am marking this topic resolved, but please update it if you have problems or further questions regarding the above suggestions. Thanks for your interest in the plugin.