I added this custom post named "candidates" and I wanted to generate a shortcode [candidate] with parameters to make it [candidates id="123"]. Here is my code so far. I wanted to display the thumbnail picture, title, and a button that says "see comments" that redirects to the single post.
// >> Create Shortcode to Display Movies Post Types
function diwp_create_shortcode_candidates_post_type(){
$args = array(
'post_type' => 'candidates',
'posts_per_page' => '1',
'publish_status' => 'published',
);
$query = new WP_Query($args);
if($query->have_posts()) :
while($query->have_posts()) :
$query->the_post() ;
$result .= '<div class="candidates-item">';
$result .= '<div class="candidates-poster">' . get_the_post_thumbnail() . '</div>';
$result .= '<div class="candidates-name">' . get_the_title() . '</div>';
$result .= '</div>';
endwhile;
wp_reset_postdata();
endif;
return $result;
}
add_shortcode( 'candidates', 'diwp_create_shortcode_candidates_post_type' );
// shortcode code ends here