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.
Viewing 10 posts - 1 through 10 (of 22 total)
  • Anonymous
    #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
    #193158

    You 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.

    Anonymous
    #193169

    Exactly i want to to fetch the field data from a related Post Object.

    Please where i can find this ID?

    Trevor
    #193175

    That data is stored in a field in the post being displayed (the relational object field), so you have to get that first.

    Anonymous
    #193181

    For my test I create only 3 entry.

    Each of this entry have an id (“12220”, “12222”, “12210”)

    I think is not that.

    I am sorry i am a beginner

    Trevor
    #193185
    This reply has been marked as private.
    Anonymous
    #193191
    This reply has been marked as private.
    Trevor
    #193219
    This reply has been marked as private.
    Anonymous
    #193223
    This reply has been marked as private.
    Trevor
    #193228
    This reply has been marked as private.
Viewing 10 posts - 1 through 10 (of 22 total)