Support

Account

Home Forums General Issues Display SUB field from a options page with relationship field on chosen pages

Solved

Display SUB field from a options page with relationship field on chosen pages

  • On a options-page i have a flexible field named “People” where i have the row “Name” and “Age” + a relationship field named “Location on Website”. Now if i write a new “People” entry i have the 2 fields “Name” and “Age” + the relationship fields with all pages and posts listet. Now when ich choose a page in the relationship field (e.g. “Sports”) i want the Guy to be visible in the sidebar of the page that i have chosen. Is this possible with sub-fields? i tried some example code but got nothing …

  • You’d want something like:

    if ( have_rows('people', 'option') ) while ( have_rows('people', 'option') ) {
      the_row();
      if ( in_array( get_the_ID(), array_merge( get_sub_field('relationship_field_for_posts'), get_sub_field('relationship_field_for_pages') ) ) {
        the_sub_field('name');
        echo '<br>';
        the_sub_field('age');
      }
    }

    This code would cycle through all items in the people repeater, then check to see if the current ID is in either the relationship field for posts, or the relationship field for pages. If found in one of those fields, it will print out the info.

  • When i use your code i get an error. This is my code:

    <?php if( have_rows('info_boxen_anlegen', 'option') ) : 
    
       // loop through the rows of data
        while ( have_rows('info_boxen_anlegen', 'option') ) : the_row(); ?>
    
            <?php if( get_row_layout() == 'normale_info_box' ): ?>
    
    		<?php the_sub_field("ib_normal_uberschrift"); ?>
    
    <?php endif; endwhile; endif ?>

    This shows all my info-boxes. But i only want to show (in this case) the one with the chosen page:

    fields

    In short: I just want to show this info-box on the page “Über uns”, nowhere else.

  • This reply has been marked as private.
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Display SUB field from a options page with relationship field on chosen pages’ is closed to new replies.