Target Parameters (Sort Order)

Add the query parameter redirect_to to the URL of your blog. This parameter is mandatory.

Values can be:

  • last or latest – The URL will redirect((Technically the URL is rewritten, i.e. the browser address bar will show the new URL.)) to the latest post.
  • first or oldest – The URL will redirect to the first (oldest) post.
  • prev or previous – The URL will redirect to the previous (by time) post of the same post type.
  • next – The URL will redirect to the next (by time) post of the same post type.
  • random – The URL will redirect to a random post.
  • custom – The post will be determined according to the mandatory parameter orderby and the optional parameter order. Possible values for orderby are listed here. By default, order is “DESC” (descending – starting from the highest value, the later time or the bottom position in alphabetic order). Alternatively you can set it to “ASC” (ascending).

Obviously, the parameter “custom” lets you achieve the same as “latest”, “first” and “random”. These shortcuts exist just for convenience and readability.

Previous or next post

In contrast to the other parameters, “prev”/”previous” and “next” make only sense when used on the URL of a post (of any post type). Technically they also let you flip through pages but will lead to unexpected results when a page is of a special page type, like the home page or any archive page where you show a list of posts.

With “prev”/”previous” and “next” you don’t need to use post_type, because the plugin will infer the post type from the current post. All other parameters need post_type=… unless the post type is the default “post”.

If you use ?redirect_to=prev or ?redirect_to=next in a link or button, make sure that you don’t add a forward slash (“/”) in front of the question mark so that the link will include the full post URL. /?redirect_to=prev would start at the root address, like https://www.example.com/?redirect_to=prev, while you need https://www.example.com/show-me-a-post/?redirect_to=prev.

The values “prev”/”previous” and “next” can be combined with “offset” in order to skip one or more posts.

Retrieving the 2nd, 3rd, etc. matching post

If you want to show the 2nd, 3rd, etc. matching post, you can use the parameter offset. The offset will be counted additionally. So “offset=1” means the 2nd post. If the offset is too high compared to the amount of matching posts, the procedure for “no posts found” will be run.

Random of a subset

Use the parameter count together with random in order to pick a random post out of a subset. The value of count determines the N most recent posts or the N oldest posts (if N is prepended by a minus).

The parameter count can be combined with offset.

Random with a bias

Use the parameter bias to pick a post from a subset (defined with count and – optionally – offset) with a higher probability than the rest. The value of bias is a percentage (without the % sign).

Examples

Redirect to the latest post:

http://www.example.com/?redirect_to=latest

Redirect to the 2nd-latest post:

http://www.example.com/?redirect_to=latest&offset=1

Redirect to the post with the highest number of comments:

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

Redirect to a random post. Pick one from the latest 10 with a probability of 80% and from the rest with a probability of 20%:

http://www.example.com/?redirect_to=random&count=10&bias=80

(Note: Replace everywhere “www.example.com” with your blog’s URL.)

Find many more examples on the example page.