Support

Account

Home Forums General Issues can't get my relationship working on a widget

Solved

can't get my relationship working on a widget

  • Hi, love the plugin, life would be lost without it. I have a small issue i have spent a whole day trying to figure out.

    I have a wordpress page, which has relationship custom field, so i can select the top 10 articles and list them on that page, it works well.

    But to have it as a widget to show on the homepage, i just can’t get it working, i just can’t figure it out. I obviously need to use the page id somehow.

    <?php

    $posts = get_field(‘top10’, false, false);

    if( $posts ): ?>

      <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
      <?php setup_postdata($post); ?>

    • “><?php the_title(); ?>
      <span>Custom field from $post: <?php the_field(‘author’); ?></span>
    • <?php endforeach; ?>

    <?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>

  • if i have the following, the var dump shows the correct post id, but the get_the_title shows the latest post in the correct count, so its picking up the top 10 number, but showing the wrong post? anyone please have any ideas??

    <?php 	
    $post_id = 129;
    echo '<pre>';
    var_dump( get_field('top10s', $post_id, false) );
    echo '</pre>';
    $topten = get_field('top10s', $post_id, false);
    if ($topten) {
    	foreach ($topten as $top) {
    	echo get_the_title( $top->ID );	
    	}
    }
    ?>
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘can't get my relationship working on a widget’ is closed to new replies.