1

It's my understanding that the_excerpt() will display the excerpt, if you have made an explicit one, or the first few paragraphs of the actual content, if you did not.

In my case however, it only shows excerpts when one is declared, never uses a fallback.

I like to know what could cause this? I'm using timber and a foundation theme that I've been developing for the past couple of years. It's well orginized. The only thing I can find related to teh matter is thees parts:

// Exerpt length
function init_excerpt_length()
{
  return 24;
}
add_filter('excerpt_length', 'init_excerpt_length');

// Change the suffix
function init_excerpt_sufix($txt)
{
  return str_replace(' [...]', '…', $txt);
}
add_filter('get_the_excerpt', 'init_excerpt_sufix');

Witch to me looks A-OK


The code I use whre the problem appears:

$context['blog_posts'] = Timber::get_posts(
[
  'suppress_filters'  => 0,
  'numberposts'       => 10,
  'offset'            => ($context['page'] - 1) * 10,
]);

print_r($context['blog_posts']);

I tried using wp_get_recent_posts that resulted in the same result.


My thoughts is that this is related to wpml and the messed up import export I just did. But then again, I don't see how this problem could be related to the database.

1 Answer 1

0

It was ofc me who misunderstood how it all works. The WP_Post instance will not generate the excerpt for you, witch makes sense, less overhead when not using it.

I had to loop through it, sense I don't have access to this logic in the view because of timber.

$context['blog_posts'] = get_posts(
[
  'suppress_filters'  => 0,
  'numberposts'       => 10,
  'offset'            => ($context['page'] - 1) * 10,
]);
foreach ($context['blog_posts'] as $post)
{
  setup_postdata($post);
  $post->post_excerpt = get_the_excerpt();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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