I converted the single custom field example from the following link (https://www.advancedcustomfields.com/resources/query-posts-custom-fields/) to work for my website, and at first it worked fine, but is now not. I have it set up to do the following: find all entries that meet a certain criteria, display each of those entries with other assorted field in a table row. It works, technically, but all of a sudden, it started adding an extra row at the very top, with just one field filled in. You can view this happening over at http://ohana.church/sermon-series/restart/ . What I have happening, is this page calls for a php file that has the code. The weirdest part of this is that the piece at the bottom of this page (http://ohana.church/speakers/Wayne-Surface/) uses an almost identical piece of code, but displays properly. Here is what I have being done for reference. Let me know if you have any other questions, and thanks ahead of time for help!
<?php $name = get_field('series_title'); // args $args = array( 'numberposts' => -1, 'post_type' => 'page', 'meta_key' => 'series_title', 'meta_value' => $name, 'order' => 'ASC' ); // query $the_query = new WP_Query( $args ); ?> <?php if( $the_query->have_posts() ): ?> <div> <table class="SeriesTable cols-8 table-hover"> <thead> <tr> <th class="SeriesField SeriesFieldCounter"></th> <th class="SeriesField SeriesFieldNothing"></th> <th class="SeriesField SeriesFieldSeries" scope="col">Series</th> <th class="SeriesField SeriesFieldTitle" scope="col">Title</th> <th class="SeriesField SeriesFieldSpeaker" scope="col">Speaker</th> <th class="SeriesField SeriesFieldDate" scope="col">Date</th> <th class="SeriesField SeriesFieldReference" scope="col">Bible Reference</th> <th class="SeriesField SeriesFieldSoundcloud" scope="col">Audio</th> </tr> </thead> <tbody> <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?> <tr> <td class="SeriesField SeriesFieldCounter"></td> <td class="SeriesField SeriesFieldNothing"> <a href="http://ohana.church/sermons/<?php the_field('short_title'); ?>/"><i class="fa fa-play-circle"></i></a> </td> <td class="SeriesField SeriesFieldSeries"> <a href="http://ohana.church/sermon-series/<?php the_field('series_short_title'); ?>/"><?php the_field('series_title'); ?></a> </td> <td class="SeriesField SeriesFieldTitle"> <a href="http://ohana.church/sermons/<?php the_field('short_title'); ?>/"><?php the_field('title'); ?></a> </td> <td class="SeriesField SeriesFieldSpeaker"> <a href="http://ohana.church/speakers/<?php echo str_replace(' ','-',get_field('speaker_name')); ?>/"><?php the_field('speaker_title'); echo ' ';the_field('speaker_name'); ?></a> </td> <td class="SeriesField SeriesFieldDate"> <?php the_field('date'); ?> </td> <td class="SeriesField SeriesFieldReference"> <a href="https://www.biblegateway.com/passage/?search=<?php the_field('bible_reference_book'); ?>%20<?php the_field('bible_reference_chapter_verse'); ?>&version=KJV" target="_new"><?php the_field('bible_reference_book'); ?> <?php the_field('bible_reference_chapter_verse'); ?></a> </td> <td class="SeriesField SeriesFieldSoundcloud"> <iframe width="100%" height="100" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/<?php the_field('soundcloud'); ?>&show_artwork=false&auto_play=false&show_playcount=false&color=606060&sharing=false"></iframe> </td> </tr> <?php endwhile; ?> </tbody> </table> </div> <?php endif; ?> <?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
It’s possible that you have an empty page with ‘series_title’ field set on that page. You can check it by using this code:
$the_posts = get_posts($args); echo "<pre>"; var_dump($the_posts); echo "</pre>";
That code will show the list of pages and its ID. Then you can check from the backend if you have that page or not.
I hope this helps.
Well this helped me solve the problem by thinking about it. Basically what was happening is this: I have two separate ACF groups; sermons and series. Every sermon falls into a series, so I had “series_title” as a field name in the sermons field group. In the series field group, I also had “series_title” because, obviously, the series needs a title. I wasn’t thinking about how my code pulled from every group, anything that had “series_title”, so that top row was the entry for the series “Restart”, and thus had none of the other fields filled out because that entry didn’t have those fields at all. Does that make sense? I fixed it by changed the sermons field group to have “series_name” for the field instead of “series_title”.
You must be logged in to reply to this topic.
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!
📣 “ACF Chat Fridays”— Advanced Custom Fields (@wp_acf) January 31, 2023
The ACF team holds their first open office hours this Friday! Come and talk ACF, and ask questions about building sites with the plugin.
We’d love to see you there!
📆 Friday 3rd Feb - 3pm UTC
👉 Register here - https://t.co/3UtvQbE4CU pic.twitter.com/oTwW9K1XQ0
© 2023 Advanced Custom Fields.