Snippet Shortcodes

Documentation and tips for setting up Snippet Shortcodes on your WordPress site.

More:
WordPress.org / GitHub / YeKen.uk

[sv slug="sc-db-value-by-id"]

The following shortcode are only available in the Premium version of the plugin.

Note: By default, this shortcode is disabled. To enable, please read the last section.

Fetch a value from the given MySQL table. Specify which column the value should be fetched from as well as specify which column should be matched against for the given key.

For example, the following shortcode usage, will run the SQL specified below.

[sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]

Pseudo MySQL:

Select {column} from {table} where {column-to-search} = {key}

Actual MySQL:

Select user_login from wp_users where id=3

Shortcode Arguments

The shortcode supports the following arguments:

Argument Description Options Example
table MySQL table to search text [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
cache If enabled, cache the results of the SQL query for the number of seconds specified by True (default) or False [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d" cache=false]
cache-duration Number of seconds the data should be cached for (before hitting the database again) Number, default 3600 seconds (1 hour) [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d" cache=true cache-duration=60]
column MySQL table column to return text [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
column-to-search MySQL column to use in Where clause text [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
key Value to compare against colum-to-search text [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
key-format To stop SQL injection, a format (either numeric or string) must be specified for the key Either "%d" (for a number) or "%s" for a string [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d"]
message-not-found Message to display if no value can be found for the given key. Either blank or text [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key="3" key-format="%d" message-not-found="Could not find user"]

Enabling this shortcode

This shortcode can be enabled within the WP Admin on the page "Snippet Shortcodes" > "Settings". Simply set the setting '"sc-db-value-by-id" shortcode enabled?' to "Yes".

The following filter can also be used to force the setting to always be "No".

add_filter( 'disable-ss-sc-db-value-by-id', function( $default ){ return true; } );