I have reproduced your environment using the same theme and the same plugin. Out of the box, the plugin does not register the CPT with excerpt
. You need to register it:
add_post_type_support('advert', array('excerpt'));
This should go in functions.php
of your (child?) theme.
My only question is: how and why were you getting excerpts on singular pages if the post type does not have excerpts enabled? I assume it’s a WP feature/bug
that is not the excerpt itself, but the trimmed/stripped version of content (55 chars by default) WP builds and I am guessing it does it without checking if excerpts are enabled for that particular post type.
Alternatively, you could just add excerpt
to line 108 of wpadverts/wpadverts.php
, but if you do this you will lose this mod if you ever update the plugin.
UPDATE
I think I finally understood what you asked for in the first place. My own testing of the plugin and theme is here. I do not know why the_excerpt()
does not return a trimmed down version of the content on advert category pages for posts that do not have manual excerpts. But, to fix this problem, I made a “custom excerpt” for use in list-item.php
. Here it is:
<div class="advert-post-excerpt">
<span class="advert-excerpt">
<?php
global $post;
$limit = 55;
$content = strip_tags($post->post_content);
echo has_excerpt($post->ID) ?
$post->post_excerpt :
( strlen($content) > $limit ?
substr($content, 0, $limit).'...' :
$content
)
;?>
</span>
</div>
Change 55
to the desired excerpt length. The code above should replace your initial:
<div class="advert-post-excerpt">
<span class="advert-excerpt"><?php echo get_the_excerpt(); ?></span>
</div>
I’m a practical guy, if it doesn’t work one way, I find a way. However, if anyone could enlighten me on why the_excerpt()
returns null
in this case, I’d thank them.