The following is problematic in the OP’s code snippet:
- Missing
shortcode_atts()
for default attribute handling. - Incorrectly defining the shortcode’s input argument, use instead function
create_my_shortcode( $attr = [], $content = null ){ ... }
- Not escaping user input, check e.g.
wpdb::prepare()
. We want to avoid possible SQL injections. - Uses hardcoded table prefix,
wp_
, instead of$wpdb->prefix
. - Fetches all fields with
SELECT *
. Better to fetch only what’s needed. - Not returning the output from the shortcode’s callback.
- Incorrectly setting the shortcode’s attributes, should be called from the content with e.g.
[my_ttcode key1="V001" key2="Sarpanch"]
but use better descriptive attributes instead ofkey1
andkey2
. - Maybe not using
WP_DEBUG
, when developing, as there would be PHP notices from eg. not initializing the$data
string before appending to it. - Not indenting the code properly, makes it harder to maintain and understand code projects.
Check e.g. the Codex for more general info on shortcodes.
Hope it helps!