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 trying to filter out the excerpt by character length for a plugin called "List Category Posts". I've been trying to get the excerpts working for the past week, but nothing is doing the trick. The plugin actually comes with a feature that allows you to post the excerpt or not, then filter it by character length.. by adding "excerpt_size=" in the shortcode. But unfortunately, it doesn't work at this time, and I've tested it with multiple different themes. Anyways, here is the code it uses to get the excerpt:

public function get_excerpt($single){
    if (
            $this->params['excerpt']=='yes' &&
            !($this->params['content']=='yes' &&
            $single->post_content) ){
        /*
         * Strip shortcodes - #5
         * http://codex.wordpress.org/Function_Reference/strip_shortcodes
        */
        if($single->post_excerpt){
            return $single->post_excerpt;
        }
        $lcp_excerpt = strip_shortcodes(strip_tags($single->post_content));
        $exc_lim = intval($this->params['excerpt_size']);
        $lcp_excerpt = mb_substr($lcp_excerpt, 0, $exc_lim) . '...';
        return $lcp_excerpt;
    } else {
        return null;
    }
}

and the excerts are set by default like so (I've tried changing the 'excerpt_size' default parameter below, and it did not work):

'excerpt' => 'no',
'excerpt_size' => '255',

I don't even need a grand solution to get the whole shortcode excerpt filter to work with any number I enter. If anyone could help me get it to work so all the excerpt character lengths are say, 100. That would be amazing!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You need to have

'excerpt' => 'yes',
'excerpt_size' => '100',
'content' => 'no'

... when get_excerpt runs. You can set $params like that but what you posted is not all of the code. It is using $this which means it is part of a class (or you'd get errors). Somewhere in that class something might be altering the defaults, and I suspect something does. If that doesn't work you need to edit your question to provide more of the code.

share|improve this answer
add comment

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.