i am looking for a solution to get the category of the related post. I created a shortcode (@buttered_toast helped me, thanks for that) that can be inserted in a post. This shows custom IDs/posts. It works fine, but unfortunately it does not show the associated (main)category of each post. In all attempts, only "array" was output or the category of the post in which the shortcode is inserted.
function posts_shortcode($atts) {
$atts = shortcode_atts( array(
'id' => ''
), $atts );
$html = '<div class="posts">';
foreach (explode(',', $atts['id']) as $post_id) {
$html .= '<div class="post">';
$html .= '<div class="thumb">' . get_the_post_thumbnail($post_id, 'medium') . '</div>';
$html .= '<span class="badge">' . CATEGORY HERE . '</span>';
$html .= '<div class="content">';
$html .= '<h4>' . get_the_title($post_id) . '</h4>';
$html .= '<p>' . get_the_excerpt($post_id) . '</p>';
$html .= '</div>';
$html .= '</div>';
}
$html .= '</div>';
return $html;
}
I think its easy for you guys, but i dont have any idea anymore…