Filter Parameters (Set the Post Base)

You can combine the target parameters with filter parameters in order to narrow down the scope of considered posts to a certain subsample. Time parameters refer to the time of publishing. Supported are (according to superficial testing and the documentation):

authorauthor ID or comma-separated list of IDs
author_nameuses user_nicename (Try the last piece of the URL of the author’s page.)
catID or comma-separated list of IDs of categories; prepend a “-” to a number to exclude this category.
category_namecategory slug
before

(or date_query_before)

Only posts from before the specified time will be considered.
The value can be anything that can be understood by strtotime(), including relative formats like “last monday” or “1 year ago”.1
after

(or date_query_after)

See before. This one restricts the choice of posts to those after the specified time. You can combine both parameters.
dayday of the month
excludecomma-separated list of post or page IDs
hour
ignore_sticky_postsSet to 0 if you want to consider the stickiness of posts and sort sticky posts to the front. By default sticky posts are treated as normal posts (ignore_sticky_posts=1).2
minute
monthnummonth as number 1-12
post_typeDefault is “post”. Needs to be set if you want to redirect to anything else, like “product“.
Note for custom post types: Requires has_archive in the definition of that post type.
ssearch for a keyword
second
tagtag slug
wweek of the year
has_password1 for posts with passwords; 0 for posts without passwords
tag_idtag ID
comment_countFilter by the number of comments. Negative values search for posts that have not that number of comments. (requires WP 4.9+)
comment_count_minFilter by a minimum number of comments (>=). (requires WP 4.9+)
comment_count_maxFilter by a maximum number of comments (<=). (requires WP 4.9+)

Example

Redirect to a random post from the past month:

http://www.example.com/?redirect_to=random&after=1%20month%20ago

Find many more examples on the example page.


Show 2 footnotes
  1. Write spaces as “%20”. Pay attention to key words like “year”, which are in singular.
  2. Please note that we decided to reverse the default WordPress behavior in order to provide the functionality that most users would expect.

How do you rate this article?