The post ID filter for Views allows to return or exclude one or several posts by their IDs. You can also add the IDs as a URL parameter or an attribute when you add your Views shortcode to a page.

In the Query Filter section, click on Add a filter. You’ll see different filter options.

Filter by post id – Select filter
Filter by post id – Select filter

Select the Post ID filter and you will be presented with the filter options:

Filter by post id – Filter values
Filter by post id – Filter values

You now have several options to set the post IDs you want filtered.

Include or exclude

First, you need to set what to do with the IDs that will be filtered: should the View include only posts with those IDs? Or maybe the View should return all posts but those with the filtered IDs?

Specific post ids

Select the Posts with those IDs option, and enter a single post ID, or a comma separated list of post IDs e.g. 302,12,309

Value set by URL parameter

Select Posts with IDs set by this URL parameter, and enter the name of the URL parameter you want to use, which defaults to post_ids.

When you link to the page where you have inserted your Views shortcode, you can specify the post IDs you want filtered in or our, as URL parameters.

For example:-

yoursite/page-with-this-view/?post_ids=302

or for multiple post IDs

yoursite/page-with-this-view/?post_ids[]=302&post_ids[]=12&post_ids[]=309

Value set by View shortcode attribute

Select Posts with IDs set by the View shortcode attribute, and enter the name of the attribute you want to use, which defaults to ids.

When you insert your View shortcode into a page or post, just add this attribute as a shortcode parameter:

Post id shortcode attribute
[wpv-view name="Filter by post id" ids="302,12,309"]