Manual excerpt being ignored on custom post type

by Joren   Last Updated February 11, 2019 09:08 AM

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 
        } ?>


Answers 2


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.

Joren
Joren
March 31, 2015 22:14 PM

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.

Brad Dalton
Brad Dalton
April 01, 2015 04:27 AM

Related Questions


Sort pod by fields

Updated May 25, 2015 05:03 AM

Pods: Authors to Custom Field

Updated May 30, 2017 09:08 AM