Home Forums General Issues Relationship Field: crested in an Options Page, not displaying in a widget


Relationship Field: crested in an Options Page, not displaying in a widget

    • andiszek

    • September 27, 2013 at 6:01 am

    i am having trouble displaying a Relationship field in a widget. I am sure that i am doing something wrong, but i don`t have any idea what…

    here is what i did:
    i have an Option Page, where i created a Relationship field. i want to display the data from this Relationship Field in a Widget in the Sidebar – but it`s not working.
    if i add the Relationship Field Code to the template file, it works perfectly fine.

    The Widget is a basic widget with a single Field (widget title), and it should list the data from the relationship field.

    see here:
    right sidebar, 2nd Widget: Top Destinatii 2013 – the list displays the name of the Homepage over and over again.

    scroll down the page, near the footer, and look at the list in the main column: Top Destinatii 2013 – same code from the widget (copy-pasted), and it works fine.

    what am i doing wrong? is there something special i have to take into consideration to display a Relationship field from an Options Page in a Widget?

    here is the relationship field code (which otherwise works fine in any template file):

    <?php // +++++++++ Relationship Field
    			$posts = get_field('opt_sidebar_topdestin','option');
    			if( $posts ): ?>
    				<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
    					<?php setup_postdata($post); ?>
    						<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    						<?php //the_field('prod_shortdescr'); ?>
    				<?php endforeach; ?>
    				<?php wp_reset_postdata(); ?>
    			<?php // +++++++++ Relationship Field
    			endif; ?>

    i appreciate your help with this issue.
    thank you in advance!

    • Elliot

    • September 30, 2013 at 3:11 pm

    Hi @andiszek

    Have you done much code debugging yet? Have you tested what value is returned by get_field('opt_sidebar_topdestin','option')?

    Can you confirm that any code is running in this widget correctly?


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.