I created a function in my functions.php to show related posts for a custom posttype. Because the original developer used a themebuilder, I need to use a shortcode to display this function on the front-end.
A part of the code I use is
if($related_cats_post->have_posts()): while($related_cats_post->have_posts()): $related_cats_post->the_post(); $postsList .= '<li><a href="' . the_permalink() . '">' . the_title() . '</a></li>'; endwhile; return '<ul>' . $postsList . '</ul>';
It gets the job almost done. The only problem is that because I use the_permalink() and the_title(), the link and the title shows up on top of the page and not in the unordered list as they supposed to do. I don't know why this happens and how to fix this. Is it maybe because I call the function within a shortcode?
Is there a way to fix this?