Home › Forums › General Issues › Loop ALL fields within sidebar › Reply To: Loop ALL fields within sidebar
Hi John,
You’re a genius. Thank you. It’s working perfectly.
Below is my final code for anyone else needing this fix. Note: I’ve added a hyperlink around the logo to the relevant post.
<?php $args = array(
'post_type' => 'post', // or your post type
'posts_per_page' => -1, // get them all
'meta_query' => array(
array(
'key' => 'logo',
'value' => '',
'compare' => '!='
) ) );
$query = new WP_Query($args);
if ($query->have_posts()) {
global $post;
while ($query->have_posts()) {
$query->the_post();
echo '<a href="' . get_permalink() . '">';
echo '<img src="' . get_field('logo') . '" /></a>';
}
wp_reset_postdata();
}
?>
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've just released ACF 5.12.3 with a security fix to prevent arbitrary file uploads to forms with ACF fields.
— Advanced Custom Fields (@wp_acf) July 14, 2022
Now that we've released this update, we recommend updating your sites as soon as possible.
© 2022 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.