For a website I’m working on, my clients would like to sometimes link other posts within a post in WordPress. I found this tutorial and tried to adapt my code to make it work for my need. Here’s what I have so far :

function linkarticles($atts) {
  $thepostid = intval($atts[id]);
  $output = '';
  $post = get_post($thepostid);
  if ($post) :
    $output .= '<article class="articles_miniatures"> <a class="img_intro" href="' . get_the_permalink($post->ID) . '">' . get_the_post_thumbnail($post->ID, 'post-thumbnail', ['class' => 'img-responsive']) . '</a><h2>' . get_the_title($post->ID) . '</h2>' . get_the_excerpt($post->ID) . '</article>';
  else :
  // failed, output nothing
  endif;
  return $output;
}
add_shortcode('include_post', 'linkarticles');

Everything works fine except for the excerpt, which displays the current page excerpt instead of the article with the ID.
Anyone knows how to fix that ?

Read more here: WordPress get_the_excerpt with ID number return current page


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: