From af71d22742d98b1c619b60e304f5013c7968d101 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 23 Sep 2014 03:37:06 +0000 Subject: [PATCH] Add two properties to `media.model.Attachments.propmap`: `include` and `exclude`, which are aliases for `post__in` and `post__not_in`. This allows you to instantiate a library that includes and/or excludes specific attachments by passing a single ID or an array of IDs. Example usage: {{{ wp.media({frame: 'post', library: {include: [414, 415]}}).open() wp.media({frame: 'post', library: {include: 414}}).open() wp.media({frame: 'post', library: {exclude: [414, 415]}}).open() wp.media({frame: 'post', library: {exclude: 414}}).open() }}} Fixes #26587. git-svn-id: https://develop.svn.wordpress.org/trunk@29759 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-models.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/js/media-models.js b/src/wp-includes/js/media-models.js index ac7ee938d6..cba928d9c2 100644 --- a/src/wp-includes/js/media-models.js +++ b/src/wp-includes/js/media-models.js @@ -1164,7 +1164,9 @@ window.wp = window.wp || {}; 'perPage': 'posts_per_page', 'menuOrder': 'menu_order', 'uploadedTo': 'post_parent', - 'status': 'post_status' + 'status': 'post_status', + 'include': 'post__in', + 'exclude': 'post__not_in' }, /** * @static @@ -1211,6 +1213,12 @@ window.wp = window.wp || {}; props.orderby = defaults.orderby; } + _.each( [ 'include', 'exclude' ], function( prop ) { + if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) { + props[ prop ] = [ props[ prop ] ]; + } + } ); + // Generate the query `args` object. // Correct any differing property names. _.each( props, function( value, prop ) {