I'm creating a shortcode in wordpress where the user can use the post title or slug of a post to pull information from a post. Everything works well except for when a post's title has an apostrophe in it.
An example of the shortcode that works with the post slug is
[card]hunters-mark[/card]
When I use the post title and the title has a apostrophe it doesn't work.
[card]Hunter's Mark[/card]
When I use the shortcode with the title of a post that doesn't contain a apostrophe everyting works so the issue is with the apostrophe. The code I use to get the post id is
$sql="select * from $wpdb->posts where (post_title='$content' or post_name='$content' ) and post_type='cards' and post_status='publish' limit 0,1";
$my_posts = $wpdb->get_results($sql);
if( $my_posts ) {
$card_id = $my_posts[0]->ID;
}
Edit:
So what is weird is that when I try to output everything by using
`$data=strpos($content,"'");
var_dump($data);
$content=str_replace("'", "\'", $content);`
It is displaying strpos("Hunter's Mark","'")=false
So it is saying that there is no ' even though there is, and and I check the database and the post title is showing exactly how I have it in the shortcode.