0

I've set up some custom post types with Pods, but can't seem to get it to display my manual excerpt. It's working fine for my normal posts.

I've tried displaying it with echo get_the_excerpt() and the_excerpt(). I've tried doing it using get_posts() and setup_postdata(). I've also tried a standard WP_Query loop.

No matter what I do, it just gives me the automatically generated excerpt.

Any ideas?

        <?php
        $posts = get_posts(array(
            'post_type' => 'press-release'
        ));
        foreach ($posts as $i => $post) { 
            setup_postdata($post); ?>
            <div class="row press appear" on-visible="{class: 'visible'}">
                <div class="columns small-3">
                    <p class="date"><?php echo get_the_date('M j Y'); ?></p>
                </div>
                <div class="columns small-9">
                    <h2><a target="_blank" href="<?php echo get_the_permalink(); ?>"><?php the_title(); ?> &nbsp; ></a></h2>
                    <div class="excerpt"><?php the_excerpt(); ?></div>
                </div>
            </div>
        <?php 
        } ?>
  • Is your "manual excerpt" just a custom field? If it is, you'll need to get its name and call its content via something like $my_excerpt = (get_post_meta( $post_id, 'my_excerpt_field_name', true )); – Pat Gilmour Mar 31 '15 at 21:55
  • We would need to see the theme code, though hacking a theme is discouraged and probably makes the question of-topic. – s_ha_dum Mar 31 '15 at 21:59
  • It's not a custom field. It's just the wordpress excerpt functionality. – Joren Mar 31 '15 at 22:05
0

Ok I figured it out. My custom post type was called press_release not press-release, and instead of returning no results, wordpress was returning some arbitrary collection of results that were broken in weird ways.

0

When you use the register_post_type function you will need to include support for excerpts:

add_action( 'init', 'press_release_post_type' );
function press_release_post_type() {

    register_post_type( 'press_release',
        array(
            'labels' => array(
                'name'          => __( 'Press Release', '$text_domain' ),
                'singular_name' => __( 'Press Release', '$text_domain' ),
            ),
            'has_archive'  => true,
            'hierarchical' => true,
            'public'       => true,
            'rewrite'      => array( 'slug' => 'press_release', 'with_front' => false ),
            'supports'     => array( 'title', 'excerpt' ),

        )
    );

}

supports

An alias for calling add_post_type_support() directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.