• Resolved jonnorstrom

    (@jonnorstrom)


    I have an MLA Gallery in my page, using the [mla_gallery] shortcode. I see that you can filter which images to show by the attachment tag or attachment category by changing the shortcode – but I need to be able to just get back the list of img IDs or URLs with an API call instead (because I’m on a single-page app managed by Vue.js).

    Is this at all possible?

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

    (@dglingren)

    Thanks for your question, which is a variation on an earlier support topic:

    Featued Image (Post_thumbnail)

    The “Random Featured Image” example plugin is available in the Settings/Media Library Assistant Documentation tab. To install the example plugin, navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. You will see a table that lists all the example plugins and gives you a “one-click” action for installing them. Type “random” in the text box and click “Search Plugins” to filter the table. You are looking for “Random Featured Image” example plugin. Find that plugin and hover over the title in the left-most column. Click the “Install” rollover action, then go to the WordPress Plugins/Installed Plugins submenu and activate it as you would any other plugin.

    The basic approach is straightforward: 1) define a custom shortcode that accepts a list of IDs and processes it, and 2) use the do_shortcode function to execute an [mla_gallery] shortcode that generates the IDs and passes them to your custom shortcode. Here’s the code from the example plugin:

    if ( self::USE_SHORTCODE ) {
    	add_shortcode( 'random_featured_image', 'RandomFeaturedImage::random_featured_image_shortcode' );
    	do_shortcode( sprintf( '[mla_gallery %1$s="%2$s" orderby=rand posts_per_page=1 mla_alt_shortcode=random_featured_image rfi_post_id="%3$d"]', $taxonomy, $chosen_name, $post_ID ) );
    	remove_shortcode( 'random_featured_image' );
    } else {
    

    The example plugin hooks the save_post action to get its parameters. You will have to figure out how to get parameters from your vue.js application in some other way.

    That gives you one approach that should meet your needs. If you need more specific guidance, any additional details about your application will be very helpful. I will leave this topic unresolved until I hear back from you. Thanks for your interest in the plugin.

    Thread Starter jonnorstrom

    (@jonnorstrom)

    This is not quite the issue – and my apologies because I realize I wasn’t specific in my original post.

    The WP API is accessible via {domain}/wp-json/wp/v2/posts or something of the sorts. I can then only requests posts tagged appropriately by wp/v2/posts?tag={tag_id} and I’m hoping to do the same thing with the media objects that your MLA Gallery returns. When I hit the API for media objects, I can’t get the Att. Tags or Att. Categories data to come back as well.

    Do you have an endpoint for that? Do you have suggestions? I can’t re-process the shortcode because our page shouldn’t ever reload. I use the shortcode to immediately get the gallery, but then I need to filter later by tags without refreshing the page.

    Thanks again, sorry if I wasn’t clear in my issue.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the additional information. It looks like you are using the WordPress REST API to access backend resources for your application.

    You wrote “When I hit the API for media … “. That’s because WordPress does not provide taxonomy support for Media Library items – one of the original reasons MLA was created.

    I have never found the time to learn and implement REST API endpoints for MLA, and I have no plans to add these features in the near future. It might be possible to use the older AJAX API to adapt the logic in the example plugin I outlined above. WordPress and MLA still use these APIs for a number of their services. If that is a possibility for your application I can investigate the work required to give you more specific help.

    I regret the news is not better, but I will leave this topic unresolved for now. Let me know if you’d like to proceed with an AJAX alternative.

    Thread Starter jonnorstrom

    (@jonnorstrom)

    I figured a different solution. I just extended the existing taxonomies onto attachments. So I can still use MLA Gallery, but with the original classifications.

    
    $taxonomies = array('category', 'post_tag');
    foreach ( $taxonomies as $tax ) {
       register_taxonomy_for_object_type( $tax, 'attachment' );
    }
    
    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the good news that you’ve found a solution for your application.

    MLA has support for adding support for the WordPress taxonomies on the Settings/Media Library Assistant General tab. I am curious if you tried that as an alternative to the PHP code you posted above, especially if you did and it did not work as expected.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Filter Gallery Images via API’ is closed to new replies.