Skip Navigation

[Resolved] How can i filter a view to show just the posts with empty excerpt

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to create a View that shows only those posts with empty excerpts.

Solution: It's not possible to filter by post_excerpt using WP_Query, so it will require custom PHP. Create a custom shortcode that returns a comma-separated list of post IDs, then feed that shortcode into the ids attribute of a View of posts filtered by Post ID in a shortcode attribute.

[wpv-view name="Your View Name" ids="[get_empty_excerpt_ids]"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by BrunoJ506 5 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1195418

I need to make a view that shows just the posts with an empty excerpt. but the excerpt is not on the list of fields opt-in for search. How can I do this?

#1195582

Hi, there's no built-in way to filter directly by post excerpt contents. WordPress's WP_Query doesn't support it, and Views queries posts using WP_Query. This means the Views query filter API won't be useful here, and unfortunately it will require custom PHP code that falls outside the scope of support we provide in the forums.

If you're able to dynamically generate a comma-separated list of the empty excerpt post IDs, then I can show you how to use a post ID filter to show only those posts. Generating that list is the challenge. It will require an understanding of WPDB queries:
https://codex.wordpress.org/Class_Reference/wpdb

#1195587

Let's assume that I can get that list, I'm a developer so that I can do even if I get to get dirty and go to PHP.

After that how can I pass the list of comma separated Ids for the filter?

#1195660
Screen Shot 2019-02-04 at 4.27.28 PM.png

Okay let's assume you create a custom shortcode that returns a list of comma-separated post IDs. In the View editor screen, look for the Query Filter section. If you can't see it, open the Screen Options tab in the top right corner and activate the Query Filter section. Then you can add a new filter to filter by post ID. In the configurations section for this filter, you can set it to respond to a shortcode attribute "ids" (see attached). Then when you place the View on your site, you can add the custom shortcode to the View's ids attribute like this:

[wpv-view name="Your View Name" ids="[get_empty_excerpt_ids]"]

You must register the custom shortcode name get_empty_excerpt_ids (or whatever you call your shortcode) in Toolset > Settings > Front-end Content > Third-party shortcode arguments. Then your View will be filtered by post ID, as provided by your custom shortcode.

#1195911

Now I have all the information to get this done, and also other filter problems. Great work.