Create Shortcode With Custom Attributes That Show DB Table Column Value
-
I have a table named ‘wp_myadmin’ with the structure below (there is only one row of data):
| id | president | vice |
| — | — | — |
| 1 | John | Doe |I want to create a shortcode with an attribute that will show data according to the column name.
For example:
- [myadmin as=”president”] will show “John”
- [myadmin as=”vice”] will show “Doe”
Here is my current code (still a regular shortcode):
function myshortcode_myadmin() { $name_president = "John"; return $name_president; } add_shortcode('myadmin', 'myshortcode_myadmin');- [myadmin] is showing “John” (static)
[myadmin as=”president] and [myadmin as=”vice”] also are showing “John”, because there is no attribute setting yet.
What I want is:
- [myadmin as=”president”] will show “John”.
- [myadmin as=”vice”] will show “Doe”.
Roughly the SQL query is:
SELECT %s FROM wp_myadminCan anybody help me or give me some reference please? Thanks a bunch!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Create Shortcode With Custom Attributes That Show DB Table Column Value’ is closed to new replies.