• For those who need a rest API to make a query to get media by taxonomy and term.

    
    // Install https://www.ads-software.com/plugins/media-library-assistant/
    // Install https://www.ads-software.com/plugins/insert-headers-and-footers/
    
    function images( object $args ) {
    	// This plugin requires MLA
    	if ( ! class_exists( 'MLAData', false ) ) {
    		return "MLAData does not exist";
    	}
    	try {
    		$per_page = $args['per_page'];
    		$current_page = $args['current_page'];
    		return MLAData::mla_query_list_table_items($_REQUEST, (( $current_page - 1 ) * $per_page ), $per_page);
    	} catch (Throwable $e) { // For PHP 7
    		return $e->getMessage();
    	} catch (Exception $e) { // For PHP 5
    		return $e->getMessage();
    	}
    	return "Empty";
    }
    
    add_action( 'rest_api_init', function () {
    	register_rest_route( 'mla_rest', '/images', array(
    		'methods'  => 'GET',
    		'callback' => 'images',
    	) );
    } );
    
Viewing 1 replies (of 1 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thank you for providing this straightforward example of accessing MLA from the REST interface. I haven’t had time to delve into the REST technology so I appreciate your contribution.

    If you haven’t already explored it I’d like to draw your attention to the “MLAShortcodes” class in class-mla-shortcodes.php. It contains a number of functions you could use in the same way your current example uses MLAData::mla_query_list_table_items() to access a wide range of data MLA can provide.

    It looks like you are using this WordPress plugin to host your PHP code:

    WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager
    By WPCode

    I am marking this topic “not a support question” but I encourage anyone with a problem or further question to post an update here. I will give you whatever help I can. Thanks for your interest in MLA.

Viewing 1 replies (of 1 total)
  • The topic ‘REST API to get Media by Taxonomy’ is closed to new replies.