Answer the question
In order to leave comments, you need to log in
How to get the number of records from the Relationship field (ACF)?
There are custom record types "Stores" and "Shopping centers".
Through the plugin ACF (Advanced Custom Fields), a field of type "Records" was created for "Stores", to indicate whether the store belongs to a shopping center. It is necessary to display the total number of stores referring to a specific (current) mall.
There is a code that doesn't work
<?php $args = array( 'post_type' => 'magaziny' ); ?>
<?php $loop = new WP_Query($args); ?>
<?php if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$song_count = count(get_field('center', get_the_ID())); ?>
<?php endwhile; ?>
<a href="<?php echo $post_href; ?>" class="item-btn">
<?php echo $song_count . ' магазинов</a>'; ?></a>
<?php else: ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
Answer the question
In order to leave comments, you need to log in
In theory, it should work. Here is a piece of working code from my project:
$solutions = get_field('solution', get_the_ID());
foreach ($solutions as $solution): ?>
<div class="device_menu_block_elem"><a href="<?=$solution->guid?>" class="device_menu_link"><?=$solution->post_title?></a></div>
<?php endforeach;
var_dump(get_field('center', get_the_ID()));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question