• Resolved cconstantine

    (@cconstantine)


    Is it possible to configure an mla_gallery short code to have it create a gallery of all images attached to a list of posts?

    I have series on my site (created with the Manage Series plugin) and I can look up the post ID for, say, 40 posts in one series. Can I get MLA to make me a gallery “all the images attached to these post IDs”?

    And even better, is there any way to somehow tell it to make a gallery of all the images, attached to the posts, which belong to this series??

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter cconstantine

    (@cconstantine)

    …I’ve tried using the post_parent attribute on the short code. That works if I specify just a single post’s ID like post_parent=42. But if I try t specify multiple parents, I get nothing, post_parent='42,43,44'

    Thread Starter cconstantine

    (@cconstantine)

    …after more research: The series management plugin creates a new taxonomy, “series”. So I tried using the [mla_gallery] shortcode and specifying series=example-slug-for-a-series and also by ID for the taxonomy term, series=1234. But neither displayed any attachments.

    I’m thinking that’s because the custom taxonomy is on the Posts, not the attachments… ?

    So my ideal solution would be a way to say “all the attachments on posts who have series=slug-for-the-series-i-want”

    ??

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your question and for all the work you have put into exploring and documenting the possible solutions.

    You wrote “I’ve tried using the post_parent attribute on the short code.“, and gave post_parent='42,43,44' as an example. You can use the “Keyword(s) Search” parameter to look for multiple parent values, e.g., s=42,43,44. MLA has special logic for this field to support the Media/Assistant submenu “Search Media” box, and it also works as a shortcode parameter.

    You wrote “The series management plugin creates a new taxonomy, “series”.” and “the custom taxonomy is on the Posts, not the attachments“. You’re right; the “simple taxonomy query” works for terms assigned to the Media Library items themselves, not to their parent.

    You can use the hooks provided by [mla_gallery] to substitute your own SQL query for selecting the items you want, i.e., your ideal solution. You can find one simple example of this technique in the “MLA Random Galleries Example” plugin. Go to the Settings/Media Library Assistant Documentation tab and click the “Example Plugins” button. Search for the “Random Galleries” example plugin and have a look. If you need more specific guidance, let me know.

    I will leave this topic unresolved until I hear back from you. Thanks for your interest in the plugin.

    Thread Starter cconstantine

    (@cconstantine)

    I found that random plugin, but I have no idea what it does. I understand PHP/classes/SQL but I’ve no idea how WP works under the hood (its db schema, “hooks”, “filters”, or even what the name=value pairs are called in the short codes.)

    I guess I’ll have to resort to hacking something together, like tagging all the photos in the posts of a given series… just a shame to have kludge another “remember to do this when posting…” process on when, conceptually it’s just (in my simplistic understanding) a tie-table query. But, as I said, I don’t know the WP schema so I can’t write the query.

    Thanks for looking.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update and for letting me know your level of WP/PHP/code comfort.

    I will try to adapt the example plugin to your specific application and post an update here when I have progress to report. I agree that “hacking something together” is a pain.

    Thread Starter cconstantine

    (@cconstantine)

    I have a plugin installed for adding site-specific code. So I should be able to drop in whatever you come up with. I’ve no problem with going a few rounds of “try this” if you’re not sure… you’d also be welcome to log into my site, I can give you an admin login with plugin editing power if you want to test on me, rather than having to mock something up.

    I’m aiming for something like…

    [mla_gallery series=foo-bar-bazzle ...]

    where “series” is the actual taxonomy created by the Manager Series plugin I’m using
    and “foo-bar-bazzle” is the slug for a term that posts have for that taxonomy
    I’ve about a 1,000 posts on my site, with series having 10 to 100 posts in them. So some of these could kick out hundreds of images.

    But it would also make sense (i think) if it ended up being something like…

    [mla_gallery tax_name=series tax_term=foo-bar-bazzle ...]

    again, I’ve no real grasp how the shortcodes get parsed . . .

    • This reply was modified 8 years, 6 months ago by cconstantine.
    Plugin Author David Lingren

    (@dglingren)

    Thanks for your comments and your patience. After some additional thought I arrived at a somewhat different and much more general approach for your requirements and other, similar applications.

    First, I have enhanced the [mla_gallery] shortcode’s post_parent parameter along the lines you tried earlier, e.g., post_parent=42,43,44. This is much more efficient than using the Keyword(s) Search parameter for that purpose.

    Second, I have developed a new example plugin, “MLA Parent WP_Query Example”, that performs a separate WP_Query to get a list of parent_post values for a subsequent [mla_gallery] query. If you install and activate the example plugin you can code something like this:

    
    [mla_gallery parent_wp_query"series=foo-bar-bazzle" ...]
    

    You can use most of the WP_Query parameters, e.g.:

    
    [mla_gallery parent_wp_query"series=foo-bar-bazzle post_type=post,page numberposts=10" ...]
    

    The above will match posts and pages, limiting the number of parents returned to 10 or fewer.

    You can add any other parameters you want, such as:

    
    [mla_gallery parent_wp_query"series=foo-bar-bazzle" orderby=date order=DESC]
    

    The above orderby and order parameters will be applied to the MLA query (not the parent query).

    I hope that makes sense. I chose this implementation because I can think of other ways to use a similar approach.

    I have uploaded a new MLA Development Version dated 20160714 that contains the post_parent enhancement and the example plugin. To get the Development Version, follow the instructions in this earlier topic:

    Shortcode not working in (special) widget

    After you install the Development Version you can easily install the example plugin. Navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. You will see a new submenu that lists all the example plugins and give you a “one-click” action for installing them.

    You are looking for “MLA Parent WP_Query Example” plugin. Find that plugin and hover over the title in the left-most column. Click the “Install” rollover action, then go to the Plugins/Installed Plugins submenu and activate it.

    I hope this works for your application. If you have problems or further questions, post an update here and I will help you get the results you need.

    Thread Starter cconstantine

    (@cconstantine)

    !

    …and today is actually my birthday. Awesome. I’ll try it tomorrow. ??

    Thread Starter cconstantine

    (@cconstantine)

    I have the 20160913 dev version of the v2.33 plugin installed, and activated.

    Under Documentation, plugins, I found the “MLA Parent WP_Query Example” plugin and installed it.

    But, Now I have “All (51)” plugins, zero active, one inactive. Clicking “Inactive (1)” gives me a listing with the one plugin. But the mouse over actions are only “Update” or “Download”. Similarly, the Bulk Actions menu also only has Update or Download.

    How do I activate the plugin?

    Plugin Author David Lingren

    (@dglingren)

    My earlier post said : … go to the Plugins/Installed Plugins submenu and activate it.

    In other words, you must go back to the WordPress Plugins/Installed Plugins screen and use the normal WordPress process to activate the plugin. Does that help?

    Thread Starter cconstantine

    (@cconstantine)

    Plugin activation: Oh, sorry. Yes, I have it activated now.

    It seems to be selecting only some of the [parent] posts though…

    I first tried this shortcode

    [code][mla_gallery parent_wp_query="series=england-and-france-2016"][code]

    And I got 62 attachments (all images, there are only images attached to the posts in that series). Then I noticed your mention of the [code]numberposts[code] parameter... I counted (I know by sight what images are on which posts ?? and realized those 62 images were from exactly 10 separate posts.

    So I thought perhaps [code]numberposts=10[code] was acting as a default to prevent a sort of 'select all' explosion. I tried setting [code]numberposts=11[/code], and I got attachments/images from only TWO posts. Then I tried

    [code][mla_gallery parent_wp_query="series=england-and-france-2016" numberposts=999 posts_per_page=999][code]

    But I still got only the 62 from 10 posts.

    Aside: initially, I thought perhaps I was only seeing the query display images _inserted_ into posts. Many of the posts in the series just have a single image set as the Featured Images. But, no, it is definitely showing media attachments as there are a few featured images being shown in the display.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for the update with your new results and the details you provided. How many of your posts are assigned to the england-and-france-2016 taxonomy term?

    There are no default values for the parent_wp_query parameters added by the example plugin. There is a WordPress setting that may be involved. If you go to the Settings/Reading submenu you will see an option labeled “Blog pages show at most”. What is the value of that setting?

    You should be able to override any default by adding parameters inside the parent_wp_query value. For example, you can try:

    
    [mla_gallery parent_wp_query=”series=england-and-france-2016 numberposts=999" posts_per_page=500]
    

    In the above example, the numberposts=999 parameter will be used for the “parent” query and the posts_per_page=500 parameter will be used for the query that returns the Media Library items for the gallery display.

    Let me know if that helps.

    Thread Starter cconstantine

    (@cconstantine)

    tl;dr: solved! It should be parent_wp_query="series=the-series-slug posts_per_page=<N>", not numbersposts.

    Trail for future readers…

    Posts in the series I’m working with: 49 published, another 5 or so are scheduled for publication. (In none of the cases below do I see images from the unpublished posts — so the behavior wrt un-published posts is as-expected.)

    WP setting for “Blog pages show at most”: It is configured to 10.

    A test of the “Pages show at most” setting…

    I set this WP config to 100 and tried this shortcode:

    [mla_gallery parent_wp_query="series=the-series-slug" posts_per_page=999]

    It works perfectly. I get every image which is attached to every published post in that series. Obviously, I do not want to leave that WP setting at 100. So I’ve set it back to 10. ??

    (Note that it’s not the posts_per_page=999 here that makes it work. The shortcode is unchanged, I just changed the WP setting from 10 to 100 and I get more posts’ attachments showing up.)

    A mistake I made previously…

    (Future readers: Look VERY carefully at the positioning of double-quotes in these shortcodes.)

    Previously, I tried specifying numberposts. But I realized that I had incorrectly set numberposts as a parameter to the shortcode. Oops:

    [mla_gallery parent_wp_query="series=the-series-slug" numberposts=999 posts_per_page=999]

    Trying it with numberposts in parent_wp_query

    I tried this:

    [mla_gallery parent_wp_query="series=the-series-slug numberposts=999" posts_per_page=999]

    I get all the attached images from only 10 posts in the series. :/

    Further grasping at straws…

    I even tried number_posts [sic] inside parent_wp_query thinking maybe it should have an underscore… no difference.

    solution…

    The parameter is actually posts_per_page (and not numberposts.) This works perfectly (again, future readers, note the position of the double-quote):

    [mla_gallery parent_wp_query="series=the-series-slug posts_per_page=999"]

    And this is what I ended up with for some added prettiness:

    [mla_gallery parent_wp_query="series=the-series-slug posts_per_page=999" columns=5 orderby=date order=ASC size=thumbnail]

    Plugin Author David Lingren

    (@dglingren)

    Congratulations! Thanks for your update with the good news and especially for the detailed notes for future readers of this topic; I really appreciate your effort.

    You are right; numberposts is an alternate name for the posts_per_page parameter. It works in the [mla_gallery] shortcode but is not allowed in the raw WP_Query performed by the parent_wp_query. I regret the confusion and inconvenience caused by my bad advice.

    I will mark this topic resolved when the enhanced post_parent handling goes out in the next MLA version. Thanks for working with me on this interesting application and for your interest in MLA.

    Thread Starter cconstantine

    (@cconstantine)

    Thank YOU for writing a custom plugin to implement it! This is HUGELY useful for my web site!

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Create gallery of all images attached to a list of posts?’ is closed to new replies.