Support

Account

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

Helping

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

  • Hello,
    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:
    http://simplicity.touchlogic.ro/
    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 ): ?>
    				<ul>
    				<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
    					<?php setup_postdata($post); ?>
    					<li>
    						<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    						<?php //the_field('prod_shortdescr'); ?>
    					</li>
    				<?php endforeach; ?>
    				</ul>
    				<?php wp_reset_postdata(); ?>
    			<?php // +++++++++ Relationship Field
    			endif; ?>
    

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

  • 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?

    Thanks
    E

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

The topic ‘Relationship Field: crested in an Options Page, not displaying in a widget’ is closed to new replies.