Display search form if no results

By default, Display Posts displays nothing if no posts were found matching your query.

You can specify content to display using the no_posts_message parameter.

[display-posts no_posts_message="No posts were found."]

Using a filter

You can also use the display_posts_shortcode_no_results filter to modify the no posts message. This is useful if you want to use the same message on all instances of your shortcode, or if you need to add something more than text, like a search form.

This code snippet goes in a core functionality plugin or Code Snippets.

Filters used:

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Leave a comment

Your email address will not be published. Required fields are marked *