Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm adding a custom column named Excerpt with Codepress Admin Columns, and would like to know specifically when the Excerpt has not been filled out. Instead WordPress shows post content automatically, if the excerpt is missing. This is also testable by switching on the "Excerpt View" from post list screen.

Implementing default_excerpt hook doesn't seem to do anything for admin side. Grepping through codebase isn't getting me anywhere in a reasonable amount of time so I'm asking for some help figuring this out.

share|improve this question
    
Are you actually writing column code or plugin does that? –  Rarst Nov 2 '12 at 14:59
    
No, I'm not writing column code. Problem is the same without any plugin, since Excerpt View is WordPress built-in feature. –  lkraav Nov 2 '12 at 15:55
    
Well even if you are not writing custom code for columns, look at the filter for the_excerpt below. –  userabuser Nov 2 '12 at 15:56

2 Answers 2

up vote 1 down vote accepted

Just illustrating this in full effect here with the filters and functions for both the adding of custom column and testing for excerpt existence.

Note, I've purposely ripped the guts out of has_excerpt to show you in effect what is occurring under the hood. You can use !has_excerpt in its place.

add_filter('the_excerpt', 'no_excerpt');
add_filter('manage_posts_columns' , 'excerpt_column');
add_action( 'manage_posts_custom_column' , 'excerpt_column_content', 10, 2 );

function no_excerpt(){
    //replace empty( $post->post_excerpt ) with !has_excerpt if you wish
    if ( is_admin() && empty( $post->post_excerpt ) ) 
    return 'not here buddy!';
}

function excerpt_column($columns) {
    return array_merge( $columns, array('excerpt_column' => __('Excerpt')) );
}

function excerpt_column_content( $column, $post_id ) {
    the_excerpt();
}

This does not take into account any efficiencies that can be had by arranging and or calling your functions by different means, this is only an example. In my test case,

"not here buddy!"

...is what will be returned when no excerpt is present. Change to suit your needs.

enter image description here

share|improve this answer
    
Yes, {get_}the_excerpt filters actually do work in admin just as well. Codepress Admin Columns fetches the content with get_the_excerpt() so I had to add_filter that, instead of just "the_excerpt" –  lkraav Nov 2 '12 at 16:18
    
The safer bet seeing as the_excerpt is just a wrapper for the former. All good! –  userabuser Nov 2 '12 at 16:23

There is has_excerpt() function that checks for manual excerpt.

Depending on your needs you can either build column output using it for logic or hook into the_excerpt and blank return if current post doesn't have manual excerpt.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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