Avatar of cstela
cstela
 asked on

How to get custom post type title, excerpt, thumbnail and permalink by post ID?

Hi there,
I have to generate several "loops" to get the title, excerpt, thumbnail and permalink of a custom post type 'charity' by post ID, because I need to target each ID with a special class (absolute-positioned map pointers).
Can you help me adjust my code so I can get it to work? What I have so far doesn't work:
<span id="chty_17">
						<?php // Charity ThirtySix  
                        $args = array('post_type'=> 'charity','post__in' => array(36));
                        $custom_query = get_posts($args);
                        foreach ($custom_query as $post) :
                        setup_postdata($post); ?>
                        <dt><?php the_title; ?></dt>
                        <dd>
                        <?php echo get_the_post_thumbnail(); ?>
                        <h2><?php the_title; ?></h2>
                        <p><?php the_excerpt; ?></p>
                        <p><a class="more" href="<?php echo get_post_permalink();?>">Find out more &raquo;</a></p></dd>
                        <?php endforeach;
                        wp_reset_postdata();?>
                	</span>

Open in new window

This code only displays the thumbnail and permalink correctly. I tried other options like the below, but the excerpt isn't included:
<?php $post_17 = get_post(17); // ABORIGINAL CHRISTIAN VOICE NETWORK ?>
                        <dt><?php echo $post_17->post_title; ?></dt>
                        <dd>
                        <?php echo get_the_post_thumbnail('17'); ?>
                        <h2><?php echo $post_17->post_title; ?></h2>
                        <p><?php echo $post_17->post_content; ?></p>
                        <p><a class="more" href="<?php echo get_post_permalink('17');?>">Find out more &raquo;</a></p></dd>

Open in new window

Please help! Thanks!!
WordPressPHP

Avatar of undefined
Last Comment
cstela

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
cstela

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy