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 am using the following code to generate a JSON feed. I need to extract the excerpt from posts, but when I run get_the_excerpt() it takes 28 seconds (yes SECONDS!) to run on my local server versus 599 milliseconds when I change get_the_excerpt() to 'hi'.

Does anybody have any idea why this is taking so long and what I can do to get it to load faster? This is on my local web server on the computer I'm using so it isn't due to a network issue.

$json = array();

while ( have_posts() ) {
  the_post();
  $yo = array('title' => get_the_title(), 'excerpt' => get_the_excerpt());
}

$json[] = $yo;
$json = json_encode($json);
share|improve this question

2 Answers 2

up vote 3 down vote accepted

The problem will likely be a (very slow) callback that is attached to your get_the_excerpt() function.

To inspect the attached callbacks, just inspect the global:

// Best hooked to `shutdown`
echo '<pre>'.var_export( $GLOBALS['wp_filters']['get_the_excerpt'], true ).'</pre>';

Then get rid of all those callbacks.

share|improve this answer
    
Thanks for the response. I tried running your code, but it printed "NULL" on the page. Any ideas? –  user1462 Nov 22 '12 at 0:37

If you want to access the POST object directly, you can global $post and directly access the post object being used.

while( have_posts() ){
    the_post();

    global $post;
    echo $post->post_excerpt;
}

If you are experiencing problems due to filters or anything else in the system, this should fix it.

share|improve this answer
    
This will successfully avoid having the filters attached. –  kaiser Nov 22 '12 at 0:27

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.