Home › Forums › Front-end Issues › Implode Post Object with "," and add "and" at last word › Reply To: Implode Post Object with "," and add "and" at last word
Thanks for the reply and support, I used array_filter()
etc. from another tutorial which I came across.
I inserted the code you gave and got some errors and realised that it’s needed more code around it. I worked through some but now get;
Warning: count(): Parameter must be an array or an object that implements Countable in C:\laragon\www\joint-venture\wp-content\themes\joint-venture\single-house_types.php on line 15
9
Warning: count(): Parameter must be an array or an object that implements Countable in C:\laragon\www\joint-venture\wp-content\themes\joint-venture\single-house_types.php on line 15
1
With this code;
<?php if( have_rows('development_plot_number') ): ?>
<?php while( have_rows('development_plot_number') ): the_row(); ?>
<?php
$development = get_sub_field('development', $post_id);
$output = false;
if (count($development) == 1) {
$output = $development[0];
} elseif (count($development) > 1) {
$last = array_slice($development, -1);
$first = join(', ', array_slice($development, 0, -1));
$both = array_merge(array($first), $last);
$output = join(' and ', $both);
}
if ($output) {
echo $output;
}
?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.