Database
-
Can you give me an example of what you mean?
Cheers!
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!”]
Yes, this is something I could potentially add in a future release.
I might try a simple one first to see it works. In essence wrapping around WP’s DB function get_var() e.g.
[sv slug=”sc-db-value-by-id” table=”users” column=”user_login” column-to-search=”id” key=”3″]
Sure: D
If you need a tester, feel free to writeHave a look at 4.1 and the new shortcode outlined here:
https://snippet-shortcodes.yeken.uk/shortcodes/sc-db-value-by-id.html
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.
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”]
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 ??
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.
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.
Ah take that back, doesn’t look like WP allows you to nest shortcodes like that in their editor.
Ah just read your comment there, so yeah, maybe replace nested shortcode brackets with something else.
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.
[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"][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"]
- The topic ‘Database’ is closed to new replies.