Title: Database
Last modified: November 11, 2023

---

# Database

 *  [chelminski](https://wordpress.org/support/users/chelminski/)
 * (@chelminski)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/database-108/)
 * Hi 😉
 * Please add database like a data source for shortcodes.

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/database-108/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/database-108/page/2/?output_format=md)

 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/database-108/#post-17194344)
 * Can you give me an example of what you mean?
 * Cheers!
 *  Thread Starter [chelminski](https://wordpress.org/support/users/chelminski/)
 * (@chelminski)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/database-108/#post-17194366)
 * In addition to WordPress, other services and applications also use the database.
   In some tables I have information, e.g. about the game account balance, recent
   activity on the game server, rank, number in the ranking, etc.
 * I would like to be able to use this data on the website. The query would be sent
   to the local database that WordPress uses (or an external one if you are able
   to do so). I would like to be able to define according to which criteria I will
   search (username, email address, metadata, etc.), and what I want to receive.
 * Example
 * [sc database db=”Database name” tb=”Table name” cl=”Column search” ud=”User data(
   username, e-mail, role etc.)” Cr=”The value of which column to receive” error
   =”What to show if no data was found”]
 * [SC database db=”wordpress_data” tb=”economy” ud=”user_display” Cr=”balance” 
   error=”Log in!”]
 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/database-108/#post-17197503)
 * Yes, this is something I could potentially add in a future release.
 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/database-108/#post-17197850)
 * I might try a simple one first to see it works. In essence wrapping around WP’s
   DB function [get_var() ](https://developer.wordpress.org/reference/classes/wpdb/get_var/)
   e.g.
 * [sv slug=”sc-db-value-by-id” table=”users” column=”user_login” column-to-search
   =”id” key=”3″]
 *  Thread Starter [chelminski](https://wordpress.org/support/users/chelminski/)
 * (@chelminski)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/database-108/#post-17207783)
 * Sure: D
   If you need a tester, feel free to write
 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/database-108/#post-17224834)
 * Have a look at 4.1 and the new shortcode outlined here:
 * [https://snippet-shortcodes.yeken.uk/shortcodes/sc-db-value-by-id.html](https://snippet-shortcodes.yeken.uk/shortcodes/sc-db-value-by-id.html)
 *  Thread Starter [chelminski](https://wordpress.org/support/users/chelminski/)
 * (@chelminski)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/database-108/#post-17243390)
 * Hi 😉
 * Somehow it doesn’t work for me
 * [sv slug=”sc-db-value-by-id” table=”wp_users” column=”user_email” column-to-search
   =”user_login” key=”chelminski” key-format=”%s”]
 * I’m not sure if I’m doing everything right. Here is a query about the email of
   the user with the login chelminski.
 *  Thread Starter [chelminski](https://wordpress.org/support/users/chelminski/)
 * (@chelminski)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/database-108/#post-17243408)
 * Sorry, it works, but instead of wp_users I have to enter only users.
 * Is it possible for me to retrieve data from tables other than WordPress? E.g.
 * [sv slug=”sc-db-value-by-id” table=”lobby_ip” column=”ip” column-to-search=”name”
   key=”chelminski” key-format=”%s” message-not-found=”Could not find user ip”]
 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/database-108/#post-17250643)
 * Just removed the WP prefix in 4.1.1, that will then allow you to query other 
   tables.
 * So you need to now put “wp_users”, but you should also be able to specify other
   tables.
 * Please review the plugin 🙂
 *  Thread Starter [chelminski](https://wordpress.org/support/users/chelminski/)
 * (@chelminski)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/database-108/#post-17252303)
 * Hi 😉
   Works great. Perfect. However, I have another crazy request. Is it possible
   for the query key to be a different shortcode?
 * **For example:**
 * [sv slug=”sc-db-value-by-id” table=”proxy_ip” column=”ip” column-to-search=”name”
   key=”**[sv slug=”sc-display-name”]**” key-format=”%s” message-not-found=”Could
   not find user”]
 * **or shortcode from another plugin:**
 * [sv slug=”sc-db-value-by-id” table=”proxy_ip” column=”ip” column-to-search=”name”
   key=”**[su_user field=”display_name”]**” key-format=”%s” message-not-found=”Could
   not find user”]
 * ________________
 * I guess you would have to change the [ ] sign to something else inside or, for
   example, define variables. _%2137%=*su\_user field=”display\_name”*_
 * **For example:**
 * [sv slug=”sc-db-value-by-id” table=”proxy_ip” column=”ip” column-to-search=”name”**%
   2137%=\*su_user field=”display_name”\*** key=”**%2137%**” key-format=”%s” message-
   not-found=”Could not find user”]
 * I don’t know much about programming 😅, but I’m trying to be helpful and figure
   out a way, because I imagine this might be difficult.
 * **That would be amazing. Users could query databases based on other data. Queries
   would be dynamic. This has endless applications.**
 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/database-108/#post-17256517)
 * That may not be too hard to do. WP has a PHP function called do_shortcode() that
   takes a shortcode as a string, executes it, and returns it’s output. I could 
   potentially run the argument through that and pass it on. That said, I’d have
   to do some extra security around it.
 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/database-108/#post-17256901)
 * Ah take that back, doesn’t look like WP allows you to nest shortcodes like that
   in their editor.
 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/database-108/#post-17256929)
 * Ah just read your comment there, so yeah, maybe replace nested shortcode brackets
   with something else.
 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/database-108/#post-17257440)
 * I’ve got it working with these two examples locally. One is an off the shelf 
   shortcode in SV and the other us a user one.
 *     ```wp-block-code
       [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key"sv slug='sc-user-id'</code>" key-format="%d"]
       ```
   
 *     ```wp-block-code
       [sv slug="sc-db-value-by-id" table="wp_users" column="user_login" column-to-search="id" key"<code>sv slug='admin-id'" key-format="%d"]
       ```
   
    -  This reply was modified 2 years, 5 months ago by [YeKen](https://wordpress.org/support/users/aliakro/).
    -  This reply was modified 2 years, 5 months ago by [YeKen](https://wordpress.org/support/users/aliakro/).
 *  Plugin Author [YeKen](https://wordpress.org/support/users/aliakro/)
 * (@aliakro)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/database-108/#post-17257459)
 * Ah the WP formatter is messing it up!!
 * Basically passing the other shortcode in as `sv slug='admin-id'`
    -  This reply was modified 2 years, 5 months ago by [YeKen](https://wordpress.org/support/users/aliakro/).
    -  This reply was modified 2 years, 5 months ago by [YeKen](https://wordpress.org/support/users/aliakro/).
    -  This reply was modified 2 years, 5 months ago by [YeKen](https://wordpress.org/support/users/aliakro/).

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/database-108/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/database-108/page/2/?output_format=md)

The topic ‘Database’ is closed to new replies.

 * ![](https://ps.w.org/shortcode-variables/assets/icon-256x256.png?rev=2402961)
 * [Snippet Shortcodes](https://wordpress.org/plugins/shortcode-variables/)
 * [Support Threads](https://wordpress.org/support/plugin/shortcode-variables/)
 * [Active Topics](https://wordpress.org/support/plugin/shortcode-variables/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/shortcode-variables/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/shortcode-variables/reviews/)

 * 16 replies
 * 2 participants
 * Last reply from: [chelminski](https://wordpress.org/support/users/chelminski/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/database-108/page/2/#post-17286415)
 * Status: not resolved