Forums › Forums › Search & Filter Pro › Show relationship ACF field in results
- This topic has 21 replies, 2 voices, and was last updated 6 years ago by Anonymous.
-
Anonymous(Private) November 8, 2018 at 1:03 pm #193155
Dear support
I would like to show acf relationship fiel in my results page.
I can display text and number fields but relationship doesn’t work.
Text field are : “cial_email”, “cial_telephone”, “cial_das”
Relationship field is : “cial_secteur” who take informations in another post named “secteur”.Regards
Fabrice<?php /** * Search & Filter Pro * * Sample Results Template * * @package Search_Filter * @author Ross Morsali * @link https://searchandfilter.com * @copyright 2018 Search & Filter * * Note: these templates are not full page templates, rather * just an encaspulation of the your results loop which should * be inserted in to other pages by using a shortcode - think * of it as a template part * * This template is an absolute base example showing you what * you can do, for more customisation see the WordPress docs * and using template tags - * * http://codex.wordpress.org/Template_Tags * */ if ( $query->have_posts() ) { ?> Found <?php echo $query->found_posts; ?> Results<br /> Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br /> <div class="pagination"> <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php /* example code for using the wp_pagenavi plugin */ if (function_exists('wp_pagenavi')) { echo "<br />"; wp_pagenavi( array( 'query' => $query ) ); } ?> </div> <?php while ($query->have_posts()) { $query->the_post(); ?> <div> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p>Mail : <?php the_field('cial_email'); ?></p> <p>Téléphone : <?php the_field('cial_telephone'); ?></p> <?php if( get_field('cial_das') ):?> <p>Univers : <?php the_field('cial_das'); ?></p> <?php if( get_field('cial_secteur') ):?> <p>Univers : <?php the_field('cial_secteur'); ?></p> <?php endif; ?> <?php if ( has_post_thumbnail() ) { echo '<p>'; the_post_thumbnail("small"); echo '</p>'; } ?> </div> <div> </div> <hr /> <?php } ?> <div class="pagination"> <div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div> <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php /* example code for using the wp_pagenavi plugin */ if (function_exists('wp_pagenavi')) { echo "<br />"; wp_pagenavi( array( 'query' => $query ) ); } ?> </div> <?php } else { echo "Aucun résultat trouvé"; } ?>
Trevor(Private) November 8, 2018 at 1:15 pm #193158You are trying to fetch the field data from a related Post Object?
So, your results Post might be ID #1234
But the Post Object found is ID #5678
So, when you use get_field, it must be like this:
get_field('cial_das', 5678)
So you must first find the ID of the relationship object to enable a lookup to be performed.
-
AuthorPosts