The Toolset View block lets you dynamically display lists of posts. You can add Query Filters to a View so that it only displays posts that meet specific criteria you choose.
On This Page
How to Add a Query Filter
- Select the main View block
- In the right sidebar, expand the Content Selection menu
- Click Add a filter
You can filter by many different options. We will go through the most popular options on this page.
Filtering Options
Each Query Filter offers different options for providing the value to filter by. The most common options are to filter by a specific value, URL parameter, or shortcode attribute.
- Filtering by a specific value means the View will always display or exclude what you tell it to.
- Filtering by URL parameter or shortcode attribute allows you to build a View once, then have it show different outputs based on how the URL or shortcode is configured.
As an example, we can look at the Post ID Query Filter.
Specific Post IDs
By choosing specific post IDs, this View will always display or exclude the posts mentioned.
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
When you link to the page that contains your View, you can specify the post IDs you want filtered in or out as URL parameters. This allows you to link to the same View throughout your site, but change what it displays based on the URL.
Select Posts with IDs set by this URL parameter, and enter the name of the URL parameter you want to use. The default is post_ids.
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
If you still use the legacy Views plugin or you want to keep your URL free of parameters, you can specify the post IDs you want filtered in or out as a shortcode attribute.
Select Posts with IDs set by the View shortcode attribute and enter the name of the attribute you want to use. The default is ids.
For example:
[wpv-view name="Filter by post id" ids="302,12,309"]
Available Query Filters
You can filter your View using any of the following Query Filters. You can also apply multiple filters to customize your output even more.
Filtering by Post ID
The Post ID filter for Views allows you to include or exclude posts based on their IDs.
Filtering by Post Status
Filtering by Post Status allows you to load only posts that match a certain status. This includes custom post statuses.
Filtering by Post Parent
You can filter Views that display hierarchical post types by Post Parent.
WordPress has a built-in post hierarchy concept which allows you to set individual posts as parents of other posts of the same type. The native Pages post type is an example of this. When you register a new post type with Types, you can specify if the post type is hierarchical or not.
This should not be confused with Types post relationships which allow you to specify parent-child relationships between different post types.
The post_parent field is a standard WordPress field stored in the wp_posts table which contains the post ID of the parent post (zero if there is no parent).
When you add a Parent Post query filter it is this field that is being compared.
Filtering by Sticky Posts
Standard WordPress posts can be marked as sticky, meaning they are shown before other posts on the posts archive (or a blog) page.
You can add a Query Filter to a View which makes the standard WordPress loop return only sticky posts, or all posts except sticky posts.
Filtering by Custom Field
Views lets you filter by as many custom fields as you need.
Filtering by Taxonomy
Filtering views by taxonomy lets you load specific content arranged using tags, categories and custom taxonomy.
Filtering by Author
With a Post Author Query Filter, you can let users view:
- Only their posts
- Posts by a specific author
- Posts by authors set by URL parameter
- Posts by authors set by a Views shortcode attribute
Filtering by Text String
You can add text search to a View using the Post search filter. This returns only posts where the specified string is found in the post title or the post body.
Filtering by Date
Views allows you to filter based on the date you published or modified a post. You can find detailed information about this filter on our page about filtering by date.
Related topics
- Filtering Toolset Views by Dates
- Enabling Legacy Version of Toolset Views
- Styling Custom Searches
- Styling Views and Archives
- Adding Custom CSS to Templates, Archives and Views
- Passing Arguments to Views
- Adding Custom JavaScript to Views, Templates and Archives
- Display Dynamic Sources Inside all Text Blocks
- Displaying Form Data
- Displaying a List of Posts on A Map
- Creating Sliders with Dynamic Post Content
- Adding Dynamic Content to Your Homepage
- Creating a View
- Creating Responsive Columns and Grids
- Display Content Conditionally
- Using Third-Party Hidden Fields