Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author YeKen

    (@aliakro)

    Can you give me an example of what you mean?

    Cheers!

    Thread Starter chelminski

    (@chelminski)

    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

    (@aliakro)

    Yes, this is something I could potentially add in a future release.

    Plugin Author YeKen

    (@aliakro)

    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″]

    Thread Starter chelminski

    (@chelminski)

    Sure: D
    If you need a tester, feel free to write

    Plugin Author YeKen

    (@aliakro)

    Have a look at 4.1 and the new shortcode outlined here:

    https://snippet-shortcodes.yeken.uk/shortcodes/sc-db-value-by-id.html

    Thread Starter chelminski

    (@chelminski)

    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

    (@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”]

    Plugin Author YeKen

    (@aliakro)

    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

    (@chelminski)

    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

    (@aliakro)

    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

    (@aliakro)

    Ah take that back, doesn’t look like WP allows you to nest shortcodes like that in their editor.

    Plugin Author YeKen

    (@aliakro)

    Ah just read your comment there, so yeah, maybe replace nested shortcode brackets with something else.

    Plugin Author YeKen

    (@aliakro)

    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"]
    • This reply was modified 6 months, 2 weeks ago by YeKen.
    • This reply was modified 6 months, 2 weeks ago by YeKen.
    Plugin Author YeKen

    (@aliakro)

    Ah the WP formatter is messing it up!!

    Basically passing the other shortcode in as sv slug='admin-id'

    • This reply was modified 6 months, 2 weeks ago by YeKen.
    • This reply was modified 6 months, 2 weeks ago by YeKen.
    • This reply was modified 6 months, 2 weeks ago by YeKen.
Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Database’ is closed to new replies.