Search
  • Sotware by
  • Christoph Amthor
Search Menu

Redirect URL to Post: Syntax

Note: This plugin is provided for free. Particularly if you use it to make money or in a profit-making context, however, I would appreciate if you could make a donation. Thank you!

Return to the main plugin page.

Actions

Add the query parameter redirect_to to the URL of your blog. Values can be:

  • last or latest – The URL will redirect1 to the latest post.
  • first or oldest – The URL will redirect to the first (oldest) post.
  • 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.

Example

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

 

Search Parameters

You can combine these actions with other search parameters in order to limit the considered posts to a certain group. 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
date_query_beforeOnly 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”.2
date_query_afterSee date_query_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
minute
monthnummonth as number 1-12
post_typenote: requires has_archive for that post_type; default is post
ssearch for a keyword
second
tagtag slug
wweek of the year
has_password1 for posts with passwords; 0 for posts without passwords
tag_idnumber of

You can also add a parameter default_redirect_to where you can specify a default destination if the other criteria returns an empty result. It accepts as value the id of a post or page. If this parameter is omitted or if the post or page with this id cannot be found, then the default destination is the home page.

Since version 0.5, you can also add parameters for tracking redirects in your statistics. Supported are Google Analytics (utm_sourceutm_campaign and utm_medium) and Piwik (pk_campaign and pk_kwd).

Example

http://www.example.com/?redirect_to=latest&tag_id=23&default_redirect_to=12&utm_campaign=my_link

 

Shortcode to create button

Since Version 0.5, you can create a button with a shortcode.  The syntax3 is:

[redirect_to_random_button]

Possible parameters are:

div_class: Class name used for the enclosing div.
button_class:
Class name used for the button.
text: Button text. Default: “Random Post”
redirect_to: Sets the query parameter. Default: “random”
params: Additional parameters. Formatted as: “key1=>value1,key2=>value2, …”

Example

[redirect_to_random_button text="Go to latest post" redirect_to="latest" params="tag_id=>23"]

You can, of course, create your own button, link or menu and just manually insert the URL.

 

 

Show 3 footnotes

  1. Technically the URL is rewritten, i.e. the browser address bar will show the new URL.
  2. You may have to write spaces as “%20”.
  3. The name is for historical reasons with “random”.
Share

2 Comments Write a comment

    • I think we solved your issue already in the WordPress forums. Please always report there.

      Reply

Leave a Comment

Required fields are marked *.