I have a shortcode, which contains the post title. This shortcode loads in the frontend the content from a post. Thats works fine:
function title_content($atts, $content = null ) {
global $wpdb;
$post_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_title = %s",$content));
$getpost = get_post($post_id);
return $getpost->post_content;
}
add_shortcode( 'content', 'title_content');
But I have in different categories posts with the same post title. So this loads sometimes the wrong content, because I don't want to use the post id or post slug in the shortcode.
I just want the the contents from posts with the right category (name "blog"), so I have no conflicts with the same post title anymore.
Has someone an idea, how I can solve this?