Home Forums General Issues Custom Post Types & Index.php


Custom Post Types & Index.php

  • I have been working on a project recently and have created 3 different post types and now require a standard blog being added. For the 3 custom blog types I overwrote the Single.php and removed the content editor.

    Obviously index.php and archives.php use content from the content editor for the excerpt. Meaning that for the blog index.php pulls in the title and nothing more.

    How do I go around displaying the content from the flexible content in the excerpt instead?

    Hope this makes sense!

    Thanks in Advance!

  • You’d have to overwrite what WordPress uses to generate the excerpt.

    You could try something like this … (untested)

    function filter_function_name( $excerpt ) {
      global $post;
      // Only do this on certain post types
      if('custom-post-type' == get_post_type($post)){  
        // Generate a 140 character excerpt
        $excerpt = substr(get_field('your_flexible_field',$post->ID),0,140); 
      return $excerpt;
    add_filter( 'get_the_excerpt', 'filter_function_name' );


Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Custom Post Types & Index.php’ is closed to new replies.