the_permalink(); returns last loaded answer on the page

3.74K viewsThemes
0

Hey guys,

I’ve been putting the_permalink(); in a jQuery code, this one actually :

<script>
$(“.share”).functionshare({
 shares: [”facebook”, “twitter”],
 url: “<?php echo the_permalink();?>”,
 text: “text to share”,
});
</script>

And I put it in answer.php so that it triggers for every answer. I also added <?php echo the_permalink(); ?> to answer.php so see if it works, and it does, it echoes the content of each answer properly (http://mysite.com/q/question-title/?show_answer=1681#answer_1681, or http://mysite.com/q/question-title/?show_answer=1332#answer_1332 for instance).

The problem is that when put in the jQuery script, the url it takes is always the one from the last answer that appears on the page, http://mysite.com/q/question-title/?show_answer=718#answer_718 in this case, and not the correct ones being http://mysite.com/q/question-title/?show_answer=1681#answer_1681, or http://mysite.com/q/question-title/?show_answer=1332#answer_1332…)

The jQuery code works if I put another url (“http://test.com”) so it seems to be an issue with Anspress / WordPress… Could you please help ?

Thanks heaps guys !!!

Hello,
This has nothing to do with AnsPress. There is something wrong with your code and initialization. Share link to your site so that I can see whats wrong in there.

0

Thanks for your help. I actually bypassed the issue by assigning an id based on the_permalink instead of the class $(.share), and it works… I don’t understand why this bug but anyway, problem fixed so it’s all good  !  🙂