Does it have security issue?
In the unlikely event that your $post
object gets replaced with something else (and at that point I'd consider the website's security as already compromised), the attacker could replace the value returned by $post->ID
with a malicious query string (a.k.a. SQL Injection).
To avoid that, as everyone else already pointed out, you should escape your query using the prepare() method from the $wpdb
object:
$mycontent = $wpdb->get_var(
$wpdb->prepare(
"SELECT `meta_value` FROM `wp_postmeta` WHERE `post_id` = %d AND `meta_key` = %s;",
array( $post->ID, 'my_seo_title' )
)
);
Out of curiosity, why are you manually retrieving the meta value from the database when we already have the get_post_meta() function (which does the whole security check automagically for you)? I mean, you could replace your code with:
$mycontent = get_post_meta( $post->ID, 'my_seo_title', true );
... and forget about writing queries by hand and/or making them secure (when not necessary).