• Resolved olimax

    (@olimax)


    Hi David
    Many thanks for a brilliant plugin and you very comprehensive feedback in this forum.
    I have a public search page using a shortcode thus;

    $posts_per_pageval = 20;
    echo do_shortcode('[mla_gallery  mla_alt_shortcode="gallery"  size="medium" link="file" posts_per_page=' .  $posts_per_pageval .   ' columns="0"  type="rectangular"  orderby="menu_order" post_parent=all  s="{+request:s+}" ]');

    This works very well
    However if there are no results it returns everything in the library.
    Any idea how I could get it to show nothing instead/
    Many thanks

    https://www.ads-software.com/plugins/media-library-assistant/

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

    (@dglingren)

    Thanks for your good words and for your question. I believe the answer will be similar to the technique outlined at the end of this recent support topic:

    Using tag cloud shortcode to display galleries

    You can use a Content Template to suppress the gallery display until you enter a search string. Try something like this:

    $posts_per_pageval = 20;
    echo do_shortcode('[mla_gallery  mla_alt_shortcode="gallery"  size="medium" link="file" posts_per_page=' .  $posts_per_pageval .   ' columns="0"  type="rectangular"  orderby="menu_order" post_parent=all  s="{+template:({+request:s+}|a-bad-search string)+}" ]');

    In this example:

    • The template: prefix says that this is a Content Template
    • The parentheses “()” around the two elements are used to group them into a list of alternatives
    • The vertical bar “|” between the two elements means “stop when you get a non-empty alternative
    • {+request:s+} will be empty unless there is a “s” parameter in the URL
    • a-bad-search string is a literal value (and thus never empty) which does not match any title or description of a media item, so the gallery will be empty if this alternative is used.

    You can read all about it in the “Content Templates” section of the Settings/Media Library Assistant Documentation tab, but the example should work as-is. Let me know if that resolves your issue.

    On my system, using “s” for the parameter did not work; I used “x” instead. Using “s” confused WordPress, which went looking for a post or page on its own. Since you are using your own PHP code, this may not affect you.

    I am marking this topic resolved, but please update it if you have any problems or questions regarding my proposed solution. Thanks for your interest in the plugin.

    Thread Starter olimax

    (@olimax)

    Brilliant
    Worked straight of of the box
    I was using the ‘s’ as I’d hijacked the search page but I can see why it may not elsewhere
    It also means I can check if it is empty and return ‘no results’ feedback
    Works with the pagination too
    Much appreciated

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘show empty results in shortcode search’ is closed to new replies.