Support

Account

Home Forums Front-end Issues Showing related posts from Page ID – from cookie

Helping

Showing related posts from Page ID – from cookie

  • Hello,
    When a user visits a page (Page A) I set a cookie with that page ID. Page A has Related Posts (pages).

    When the user visits any other page, I am trying to display Page A’s related posts based on the page ID. Here is what I have so far. Also, I get this to work for other types of ACF fields but can’t figure out the Relationship field. Help is appreciated!

    <?php
    	$posts = get_field('thanks_related_downloads', $pageid);
    if( $posts ): ?>
    	<?php foreach( $posts as $related_posts ): ?>
    		<?php echo get_the_title( $related_posts->ID ); ?>
    	<?php endforeach; ?>
    <?php endif; ?>

    Where *$pageid* is the cookie that I’m calling up that stores Page A’s page ID.

  • I don’t see anything that sticks out in your code other than the names of the variables that your using, try

    
    <?php
    	$related_posts = get_field('thanks_related_downloads', $pageid);
    if( $posts ): ?>
    	<?php foreach( $related_posts as $related_post ): ?>
    		<?php echo get_the_title( $related_post->ID ); ?>
    	<?php endforeach; ?>
    <?php endif; ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Showing related posts from Page ID – from cookie’ is closed to new replies.