WP Get

WP Get allows you to display content in posts dynamically based on URL parameters (values retrieve from $_GET in PHP).

Version: 1.1
Download: WP Get @ WordPress.org

Example Output

Click one of the links below and the example output will be displayed here.



Basic Usage

Use the get shortcode to display content based on the value of a URL parameter. For example, given the URL http://tinsology.net/plugins/wp-get/?test=1:
[get test="1"]
This is a test
[/get]

The above code will display ‘This is a test’ if the ‘purchase’ URL parameter is set to 1.
Click here to see the output.

You can also display content based on more than one parameter. The following shortcode will display content if both the ‘foo’ and ‘bar’ parameters are set to 1.
[get foo="1" bar="1"]
foobar
[/get]

Click here to see the output.

You can also display content if a parameter is not equal to the value you specify. For example
[get foo="!bar"]
Not bar
[/get]
The above shortcode will display content so long as ‘foo’ is not set to ‘bar’.

If you want to display the value of a particular url parameter you can use the get_param shortcode. The following shortcode will display the value of the ‘example’ url parameter:
[get_param param="example"]
Click here to see the output.
Note that before displaying the value of any get parameter, the get_param shortcode will convert any applicable characters to their corresponding HTML entities (for example < would be converted to &lt;).

Advanced Usage

In the above example you saw that by specifying multiple parameters you could display content only if all of the URL parameters matched the specified values. In other words [get a="1" b="2"] would display content only if the parameter ‘a’ was set to 1 and the parameter ‘b’ was set to 2. However, if you want to display content if any of the specified values match those of the URL parameters you can do so by setting the special shortcode attribute _or to 1. For example:

[get _or="1" a="1" b="2"]
A is equal to 1 or B is equal to 2
[/get]

For the above shortcode, any one of these query strings would cause the message to be displayed.

?a=1
?b=2
?a=1&b=2
?a=5&b=2
?a=1&b=7

Note that in the last two query strings, the value of one of the parameters is specified, but does not match. However, so long as at least one parameter matches, the message will be displayed.

There is another special shortcode attribute: _strict. The _strict attribute allows you to display content if a parameter is specified, but does not have a value (ex ?foo or ?foo= ). For example, using the following shortcode content will be displayed if the ‘foo’ parameter is not specified or if it is specified but has no value:
[get foo=""]
Foo isn’t specified or it doesn’t have a value
[/get]

If you use the _strict attribute however, it will only display content if ‘foo’ is specified:
[get foo="" _strict="1"]
Foo is specified but has no value
[/get]

Nested Shortcodes

The WordPress Shortcode API does not support nesting of the same shortcode. For example, the following is not valid:

[get a="1"]
	A equals one
	[get b="2"]
		B equals 2
	[/get]
[/get]

The plugin provides a second version of the get shortcode, get_n, to allow for one level of nesting. Note that ‘get_n’ functions exactly the same as ‘get’; it exists only to address this nesting issue with the shortcode API. For example, the following is valid:

[get a="1"]
	A equals one
	[get_n b="2"]
		B equals 2
	[/get_n]
[/get]

For Plugin Developers

If you’re a plugin developer and you want to utilize or provide users with WP Get functionality, without requiring them to install a separate plugin, follow these steps:

  • Download the latest version of WP Get
  • All of the plugin functionality is contained in a single class WPGetPlugin. Copy all of the code into your plugin.
  • Wrap the code you copied in a ‘class_exists’ statement. Ex:
    if(!class_exists('WPGetPlugin'))
    {
    	//WP Get code goes here
    	class WPGetPlugin
    	{
    		/*
    		.
    		.
    		.
    		*/
    	}
    	new WPGetPlugin();
    }
    

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>