page template - get_the_excerpt() inside WP_Query - link URL Incorrect

admin2025-06-04  2

I have a custom WP_Query loop, to pull out specific posts, that is working exactly as expected. The link can be retrieved from get_permalink(), as can any content that I'm requesting including get_the_post_thumbnail and get_the_category.

However, when I am calling get_theexcerpt`, the "Continue Reading" URL for the links of some posts is being returned as the current page URL, not the URL of the post that it's supposed to link to. Other posts work just fine, and the actual content that's excerpted from the posts with defective links is also fine.

If I enter in an actual excerpt, rather that allow Wordpress to create one, the link shows up correctly. When I then remove that excerpt again, the problem returns.

All pages are made in Page Builder, and about 50% of pages are affected. Even copying the page content entirely from a working post to a defective one doesn't work, nor does the inverse break a working post.

Any ideas?

while ($the_query->have_posts())
{
$the_query->the_post();

    $coverPost .= get_the_post_thumbnail(get_the_ID(), 'medium_large'); //works

    $category = get_the_category(get_the_ID()); //works
    $coverPost .= '<h4>' . $category[0]->cat_name . '</h4>'; //works
    $coverPost .= '<h2>' . strtoupper(get_the_title()) . '</h2>'; //works
    $coverPost .= '<p>'.get_the_excerpt().'</p>'; //sometimes works
}

I have a custom WP_Query loop, to pull out specific posts, that is working exactly as expected. The link can be retrieved from get_permalink(), as can any content that I'm requesting including get_the_post_thumbnail and get_the_category.

However, when I am calling get_theexcerpt`, the "Continue Reading" URL for the links of some posts is being returned as the current page URL, not the URL of the post that it's supposed to link to. Other posts work just fine, and the actual content that's excerpted from the posts with defective links is also fine.

If I enter in an actual excerpt, rather that allow Wordpress to create one, the link shows up correctly. When I then remove that excerpt again, the problem returns.

All pages are made in Page Builder, and about 50% of pages are affected. Even copying the page content entirely from a working post to a defective one doesn't work, nor does the inverse break a working post.

Any ideas?

while ($the_query->have_posts())
{
$the_query->the_post();

    $coverPost .= get_the_post_thumbnail(get_the_ID(), 'medium_large'); //works

    $category = get_the_category(get_the_ID()); //works
    $coverPost .= '<h4>' . $category[0]->cat_name . '</h4>'; //works
    $coverPost .= '<h2>' . strtoupper(get_the_title()) . '</h2>'; //works
    $coverPost .= '<p>'.get_the_excerpt().'</p>'; //sometimes works
}
Share Improve this question asked Jan 13, 2019 at 4:01 JoePJoeP 1011 bronze badge 2
  • 2 get_the_excerpt() does by default not add a link; codex.wordpress/Function_Reference/get_the_excerpt - please check your theme or plugins for related filter functions; see also developer.wordpress/reference/functions/the_excerpt – Michael Commented Jan 13, 2019 at 5:19
  • Oh, really? This is running from a child theme of Coraline, so I'll investigate that. Thank you – JoeP Commented Jan 13, 2019 at 13:18
Add a comment  | 

1 Answer 1

Reset to default 1

you can remove read more link by adding this filter to functions.php then add permalink to your loop

function new_excerpt_more($more) {
   global $post;
return '..';   }add_filter('excerpt_more', 'new_excerpt_more');
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749016880a315649.html

最新回复(0)