Support » Plugin: Media Library Assistant » Is it possible to query media by author’s role?

  • Resolved cparkinson

    (@cparkinson)


    Hello David – I hope you had a good break! Sorry to be piling on your inbox.

    I’m trying to create a set of documents that have been inserted into posts of a specific custom post type – um_groups_discussion – provided by an Ultimate Member plugin.

    On my test page: https://intranet-cfleads.pantheonsite.io/document-gallery-all-groups/

    I have this shortcode

    [mla_gallery post_parent=all post_mime_type=application/pdf size=thumbnail link=file orderby=date order=DESC columns=3 mla_caption=’{+title+}<br><span>{+author+}</span><br><span>uploaded: {+upload_date,date(“d F Y”)+}</span>’]

    I’m using a front-end editor to create posts with media uploaded to them. The uploaded media have post-parent=0, so I can’t limit the set by parent post type or taxonomy. But the media do have the correct author associated with them in the database, and the authors all have the same role.

    Is it possible to limit the result set by querying for a particular author role, rather than author id or name? Or would it make more sense to do an initial query to get all the author ids who belong to the relevant role, and then somehow pass that array of author ids to the shortcode?

    Any advice or insight you have would be much appreciated. Thanks!

    -Clare

    The page I need help with: [log in to see the link]

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

    (@dglingren)

    Thanks for your question and for the details of your application.

    There is no built-in capability to filter a gallery by the author’s role. However, one of the MLA example plugins gives you access to all the properties of an item’s author. You could use this to populate a custom field for each item containing the author’s “user_level” which is an older value for the role. Then, add a custom field filter to your [mla_gallery] shortcode.

    To install the example plugin
    Navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “substitution” in the text box and click “Search Plugins” to filter the table.

    You are looking for the “MLA Substitution Parameter Hooks 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 the example plugin as you would any other plugin. Make sure you have the latest version, 1.13, installed.

    Once the example plugin is activated you have access to an “author:” prefix to get values from the users and usermeta tables. The value you want is something like wp_user_level where wp_ is the database table prefix for your site; change it if you use a different prefix.

    To create the custom field

    1. Navigate to the Settings/Media Library Assistant “Custom Fields” tab.
    2. Scroll down to the “Add New Custom Field Rule” section on the left-hand side of the page.
    3. Click “Enter new field” and type the name of a new custom field, e.g., “Author Role”.
    4. Change the Data Source dropdown to “– Template (see below) –”.
    5. Enter “([+author:wp_user_level+])” in the Meta/Template text box. Use the right prefix for your site.
    6. Check the “MLA Column” box if you want to display the field as a column in the Media/Assistant submenu table.
    7. Leave the “Quick Edit” box unchecked.
    8. Leave the “Bulk Edit” box unchecked.
    9. Select “Replace” for “Existing Text”.
    10. Select “Native” for “Format”.
    11. Select “Text” for “Option”.
    12. Check the “Delete NULL Values” box to avoid storing empty values.
    13. Leave the default “Status”, “Active” .
    14. Click “Add Rule” to create the new rule.

    Once that’s done you can hover over the rule name and use the “Execute” rollover action to create values for your existing items. This may take some time.

    To use the custom field
    The “Author Role” custom field will have a number corresponding to the user’s role:

    • 10 – administrator
    • 7 – editor
    • 2 – author
    • 1 – contributor
    • 0 – subscriber

    You can add “Simple Custom Field Parameters” to your shortcode to filter the display, replacing post_parent=all:

    [mla_gallery meta_key='Author Role' meta_value='10' post_mime_type=application/pdf size=thumbnail link=file orderby=date order=DESC columns=3 mla_caption='{+title+}<br><span>{+author+}</span><br><span>uploaded: {+upload_date,date("d F Y")+}</span>']
    

    where meta_value='10' will return items owned by administrators.

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the example plugin or the above suggestions. Thanks for your interest in the plugin.

    Thread Starter cparkinson

    (@cparkinson)

    Okay, that makes sense to me. I’m familiar with the old “user level” field.

    Thanks so much for your detailed reply! I appreciate the time you took to type this all out. I’ll give it a try.

    cheers,

    Clare

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.