Examples of WordPress Redirects to Posts

On this page you find examples how to use the parameters of the free WordPress plugin Redirect URL to Post for particular applications. Replace www.example.com with your own domain.

Redirect to a random post

Simple redirection to a random post

www.example.com?redirect_to=random

Random of another post type

Redirect to a random WooCommerce product:

www.example.com?redirect_to=random&post_type=product

Random of a subsample

Redirect to a random post among the latest 5 posts:

www.example.com?redirect_to=random&count=5

Redirect to a random post among the latest 5 posts, shifted by 2 posts (that means a random from the posts number 3 to 7, counting from the latest):

www.example.com?redirect_to=random&count=5&offset=2

Redirect to a random post among the oldest (first) 5 posts:

www.example.com?redirect_to=random&count=-5

Random with a bias

Redirect to a random post. Prioritize one of the latest 20 posts with a probability of 80% and consider the rest with a probability of 20%.

www.example.com?redirect_to=random&count=20&bias=80

Random, not repeating posts

Redirect to a random post, going through all posts, then redirect to the page or post with the ID 222.

www.example.com?redirect_to=random&each_once=222

Redirect to a random post, going through all posts, then start over again.

www.example.com?redirect_to=random&each_once=rewind

Random, using the time lock

Redirect to a random post, then keep redirecting to this post for one day (60*60*24=86400 seconds), then pick another random post that we haven’t seen yet. When all posts are done, start over again.

www.example.com?redirect_to=random&lock=86400&each_once=rewind

Additional filter: time frame

Redirect to a random post that is older than 1 month but not older than 6 months:

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

Additional filter: category

Redirect to a random post that has a category with the ID 2 or 3:

www.example.com/?redirect_to=random&cat=2,3

Redirect to a random post that has not the category with the ID 2:

www.example.com/?redirect_to=random&cat=-2

Additional filter: custom taxonomy

Note: In most cases, when filtering by a custom taxonomy, you are searching among a custom post type. In that case you will also need the post_type parameter. Otherwise we would search among ordinary posts.

Redirect to a random WooCommerce product that has a post category with the IDs 2 or 3:

www.example.com/?redirect_to=random&post_type=product&custom_taxonomy_slug=product_cat&custom_taxonomy_field=term_id&custom_taxonomy_term=2,3

Redirect to a random WooCommerce product that has a product tag with the slug “sale”. When a user calls the link repeatedly, pick each item only once, then start over again:

www.example.com/?redirect_to=random&post_type=product&custom_taxonomy_slug=product_cat&custom_taxonomy_field=slug&custom_taxonomy_term=sale&each_once=rewind

Additional filter: comment count

Redirect to a random post that has no comments:

www.example.com/?redirect_to=random&comment_count=0

Redirect to a random post that has at least one comment:

www.example.com/?redirect_to=random&comment_count=-0

or:

www.example.com/?redirect_to=random&comment_count_min=1

Redirect to a random post with at least 3 comments:

www.example.com/?redirect_to=random&comment_count_min=3

Redirect to a random post with at most 10 comments:

www.example.com/?redirect_to=random&comment_count_max=10

Redirect to a random post that does not have 5 comments:

www.example.com/?redirect_to=random&comment_count=-5

Prefer Sticky Posts

Redirect to a random post, prefer one of your 5 sticky posts with a probability of 90%:

www.example.com/?redirect_to=random&ignore_sticky_posts=0&count=5&bias=90

Redirect to the first or the latest post

Redirect to the latest post:

www.example.com/?redirect_to=latest

Redirect to the first (oldest) post:

www.example.com/?redirect_to=first

Additional filter: tag

Redirect to the latest post with the tag ID 20.

www.example.com/?redirect_to=latest&tag_id=20

Additional filter: category

Redirect to the latest post with the category that has the ID 7:

www.example.com/?redirect_to=latest&cat=7

Additional filter: exclude posts

Redirect to the latest post, excluding posts with the IDs 5 and 13.

www.example.com/?redirect_to=latest&exclude=5,13

Additional filter: search string

Redirect to the first post that contains the search sting “hello”:

www.example.com/?redirect_to=first&s=hello

Additional filter: time frame

Redirect to the latest post that is older than 1 week:

www.example.com/?redirect_to=latest&before=1%20week%20ago

Redirect to the oldest post after yesterday:

www.example.com/?redirect_to=first&after=yesterday

Additional filter: author

Redirect to the latest post of the author with the ID 200:

www.example.com/?redirect_to=latest&author=200

Previous or Next

The following examples assume that we use the link of a particular post, product or page. Applying the examples on virtual pages like the front page or the posts page (where posts are listed) might lead to unexpected results (because they are often not ordered by a date).

Redirect to the previous post:

www.example.com/my-great-post/?redirect_to=prev

Redirect to the post before the previous post:

www.example.com/mind-numbing-post/?redirect_to=prev&offset=1

Redirect to the next product:

www.example.com/worst-shelf-warmer-ever/?redirect_to=next

Custom Redirects

Redirect to the post with the highest comment count:

www.example.com/?redirect_to=custom&orderby=comment_count

Redirect to the post with the lowest comment count:

www.example.com/?redirect_to=custom&orderby=comment_count&order=asc

Redirect to the post that comes first in alphabetical order (by its title):

www.example.com/?redirect_to=custom&orderby=title&order=asc

Default Redirects

Redirect to the latest post with the tag ID 23 and, if nothing was found, go to the post with the ID 34.

www.example.com/?redirect_to=latest&tag_id=23&default_redirect_to=34

Tracking of Redirects

Redirect to a random post and track the visit (Matomo):

www.example.com/?redirect_to=random&pk_campaign=random_link

Redirect to a random post and track the visit (Google):

www.example.com/?redirect_to=random&utm_campaign=random_link

Caching

Redirect to a random post with a caching time of 20 minutes (for all applicable posts – the random is picked out of the cache):

www.example.com/?redirect_to=random&cache=20

Debugging

Show the resulting link on the screen when you redirect to a random post before last month and after eight months ago, including information about caching.

www.example.com/?redirect_to=random&before=last%20month&after=8%20month%20ago&rutpdebug

Show detailed information in the debug.log, without interrupting the redirections.

www.example.com/?redirect_to=random&verbose_debug

Button

Display a button that redirects to a random item among a list of pages, specified by their IDs.

[redirect_to_post_button text="Go to a random page" redirect_to="random" params="post_type=page|include=1,2,4,35,34,35,892"]
Previous

Redirect Button