• Resolved Mintaras

    (@mintaras)


    Hi,

    Is it possible to filter images which already were used as featured images?

    I saw you have something in General > Where-used database access tuning > Featured in section

    Thanks.

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

    (@dglingren)

    Thanks for the question and for finding the “where-used” information in the Settings/Media Library Assistant General tab.

    You asked “Is it possible to filter images …” The answer is somewhat different depending on where you want to “filter”: 1) in the Media/Assistant admin submenu or 2) in the [mla_gallery] shortcode galleries.

    The “where-used” information is disabled by default because it can be quite time- and memory-intensive to calculate. For the “inserted in” values the content of every post and page must be scanned and < img > tags matched to Media Library attached files. For the gallery usage every shortcode must be executed to see which items it returns. Featured image information also requires a separate database query. All of this is done from scratch when it is needed because the code required to maintain the information as things change is very complex.

    That said, you can implement filtering in a way that might meet your needs. You can define a Custom Field mapping rule to capture the information and then use the custom field for filtering and reporting. In the Media/Assistant submenu table you can display the custom field as a column and you can sort on the column to see which items have Featured Image value and which do not. You can also define a custom table view to filter on the same do/do not status. For the [mla_gallery] shortcode you can use a meta query parameter to filter on the custom field; see the ‘ Custom Field Queries, the “meta_query” ‘section of the Settings/Media Library Assistant Documentation tab for more information.

    You might also be interested in this earlier topic:

    Searching on custom fields

    If you can give me more details on your application I can be more specifically helpful. Thanks for your interest in the plugin.

    Thread Starter Mintaras

    (@mintaras)

    Thank you for your detailed and clear explanation.

    What I want to do is to add new filter option in Media Library.
    For example now we have options to filter by:

    All media items
    Images
    Audio
    Video
    Text
    Applications
    Attached
    Unattached

    I want to add 1 more option called “Not Featured”. So I can filter out images which haven’t been attached/used as Featured Images yet.

    I thought about something like this http://wordpress.stackexchange.com/questions/200247/filter-media-by-featured-on-admin#answer-200279

    But I can’t override some hooks and filters you are using on your plugin.
    “media_view_settings”, “restrict_manage_posts”, “post_mime_types”

    Plugin Author David Lingren

    (@dglingren)

    Thanks for the additional details and the link to the StackExchange article. There are two ways you can meet your needs; both have similarities to the solution outlined in the article you found.

    First, you can use MLA’s “Library Views/Post MIME Type Processing” to implement a solution without resorting to PHP code. You can create a custom field and then create an MLA Table View that uses the custom field to add a view to the Media/Assistant submenu table. To create the custom field:

    1. Navigate to the Settings/Media Library Assistant Custom Fields tab.
    2. Scroll down to the “Add a new Field and Mapping Rule ” section.
    3. Enter “Featured in” in the field name text box.
    4. Select “featured_in_title” in the Data Source dropdown control.
    5. Change the “Option:” value to “Multi”.
    6. Check the “Delete NULL values” box.
    7. OPTIONAL: Check the “MLA Column” box if you want to see the field as a table column. Check the other boxes of you want to manually edit the field content.
    8. Click “Add Field and Map All Attachments” to create the custom field.

    To use the field in a Table View:

    1. Navigate to the Settings/Media Library Assistant “Views” tab.
    2. Make sure the “Enable View and Post MIME Type Support” box is checked.
    3. In the “Add New View” column, enter “custom-not-featured” in the Slug text box.
    4. Enter “Not Featured” as the singular and plural labels.
    5. Enter “custom:Featured in,null” in the Specification text box.
    6. Leave the Post MIME Type box unchecked.
    7. Check the Table View box.
    8. Click the “Add View” button to record your new view.

    That gives you a solution without PHP coding. The disadvantage is that the custom field is not automatically updated when items are added and removed as Featured Images.

    If you can manage some coding, you can adapt one of the MLA example plugins from an earlier topic:

    Filter by post status

    The Media/Assistant table provides all the hooks you need, but they are unique to MLA and differ from the hooks you mentioned in your post. Access to example plugins has changed since that topic was written. To find the example plugin, navigate to the Settings/Media Library Assistant Documentation tab and click the new “Example Plugins” button. Enter “view” in the text box and click “Search Plugins”. You should see the example plugin.

    The “MLA Custom View Example” plugin is the one you want. You can hover over the plugin name and click the “Download” rollover action to get a copy you can adapt to your needs. In particular, you will have to change the database query along the lines of the query shown in the StackExchange article.

    I am traveling and away from my test/development system until next Thursday. If you need more specific guidance, let me know and I will be able to help after I return home. Thanks for your understanding and your patience.

    Thread Starter Mintaras

    (@mintaras)

    Thank you for your response.

    I like the solution with PHP coding. I have installed MLA Custom View plugin. The concept is basically the same as you said.

    Question: How to add custom MIME type (hook name)?

    I would like to add custom mime type called “Not Featured” and after I select it, I would get custom view with not featured images.

    Thanks

    UPDATE:

    Is this is the one? mla_mime_types_filter

    Usage:
    function add_custom_mime_type($mime_types){
    $mime_types[ ‘not_featured’ ] = ‘Not Featured’;
    return $mime_types;
    }
    add_filter(‘mla_mime_types_filter’, ‘add_custom_mime_type’);

    • This reply was modified 9 years, 6 months ago by Mintaras.
    • This reply was modified 9 years, 6 months ago by Mintaras.
    Thread Starter Mintaras

    (@mintaras)

    I’ve tried the above but it doesn’t seem to work..

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update letting me know which alternative you’re interested in. For the PHP alternative the basic approach is to go through the source code in the example plugin and change the code to get the results you want rather than the “post status” results the example plugin starts with. You must modify the code in the example plugin for the five filters set up in the initialize function of the example plugin. Here’s an outline of the work required:

    1. In the _get_view function, change the get_var() call to make the appropriate database query. Change the $view_ variables to have the slug and labels for your new view.
    2. In the views_media_page_mla_menu function, change the case statement to match your view slug. Basically, change the “unpublished” slug throughout the plugin to your chosen value.
    3. In the posts_clauses function, change the database “pieces” to the appropriate query clauses.

    You might also want to rename the plugin and the PHP Class it contains just to prevent confusion between your modified version and the MLA version.

    I’m still on the road so I can’t develop the changes for your application. Let me know if the above suggestions make sense.

    Thread Starter Mintaras

    (@mintaras)

    I couldn’t manage to make it work with Custom View plugin. But I made it work in other way.

    I have added new view (Not Featured) in Settings > Media Library Assistant > Views and then added the code from the reference article in my functions.php. It works. Query is super slow, I need to find a way to optimize it or find a new query to get Not Featured images.

    Thank you for your help.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update. I regret that the “custom view” plugin isn’t working for you.

    When I return home I will have a look at adapting the “custom view” plugin and finding a more efficient database query for it. I will post an update here when I have progress to report.

    You could also try the “custom field” alternative I outlined above and see if that performs better for you.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your patience. I have uploaded a new MLA Development Version dated 20161027 that contains a new `mla-not-featured-view-example.php plugin. To get the Development Version, follow the instructions in this earlier topic:

    Shortcode not working in (special) widget

    Once the Development Version is installed, navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “not” in the text box and click “Search Plugins” to filter the table.

    You are looking for “MLA Not Featured View 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.

    You should also deactivate and delete the “MLA Custom View Example” plugin if you haven’t already done that.

    It would be great if you can install the Development Version and new example plugin and let me know if they work for you.

    Thread Starter Mintaras

    (@mintaras)

    Yes! Works perfectly. Thank you for your time.

    One more question. Do have any idea how to take control of Media Library popop then setting featured image? http://www.sumopaint.com/images/temp/xzxmakshqrcjkhnh.png

    And put this filter (not featured) between filters: Images, Images attached to this product, Unattached.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for taking the time to install and test the new example plugin and for the good news that it fits your needs.

    Regarding your new question, The screen shot you linked to (very helpful) is titled “Product Image”. This is not a WordPress popup that I recognize; is it part of some other plugin or theme?

    The current MLA version supports “custom table views” only on the Media/Assistant submenu screen. I will have a look and see if this can be extended to the WordPress Media Manager Modal (popup) Window.

    Thread Starter Mintaras

    (@mintaras)

    It’s just from custom post type – product (WooCommerce). If you would go to Posts > Add New > Set featured image, you would get same media modal just with “post” instead of “product”

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your patience regarding the Set Featured Image filter research.

    I have studied the WordPress code for the Media Manager Modal (popup) Window. For the “Insert Media” window there are WordPress hooks that allow MLA to add items to the item type dropdown control. I regret that I cannot find any corresponding hooks that allow changes in the “Create Gallery” or “Set Featured Image” windows. Without the hooks I have not been able to find a way to add the “Not Featured” view to the dropdown.

    Plugin Author David Lingren

    (@dglingren)

    I have released MLA version 2.41, which includes the mla-not-featured-view-example.php plugin.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the example plugin. Thanks for inspiring a new MLA example!

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Filter by featured images’ is closed to new replies.