0
votes

I have been using Advanced Custom Fields Plugin to show Related posts below post content. Yesterday I added plugin Social share by Supsystic to show share buttons on my posts and it showing greatly.

The problem is when I click on share button to share a post on facebook or other social media it fetches the post from related post field.

For example, when I click the share button on the post titled "Google Chrome Features" facebook share frame opens but the post shown in the frame is "Firefox Features". However, "Firefox features" is in the related posts field below the post "Google chrome features". Any help will worth appreciation. thanks.

1
Hi welcome to SO forums. You'll have to show us some code. - Matej Žvan
thanks for so quick response Zvan! - user31225
Do you need to see code post.single.php codes? - user31225
Can you edit the question with your (formatted) code, rather than adding it as a comment? It's not clear whether (eg) //End for each loop wp_reset_postdata(); is one line or two (ie whether that wp_reset_postdata(); call is commented out of not - Hobo
Sorry, didn't see your update - I meant to edit your question, not add an answer. You're saying the plugin's adding code share under that, and the links are wrong? What happens (a) if you put global $post; at the top of that code? Or (b) rename your variables $posts to $related_posts and $post to $related_post? Might be an issue with a global variable getting clobbered. - Hobo

1 Answers

0
votes

Advanced custom fields related posts code in post.single.php

<?php  
$posts = get_field('related_posts'); 
if ($posts) { ?> 
    <h3 class="related">Related posts</h3>
    <p>
    <?php foreach($posts as $post) { setup_postdata($post); ?>
        <li><a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php } //End for each loop
    wp_reset_postdata(); //Restores WP post data ?>
    </p>
    <hr />
 <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php } //End if ?>