Issues with Relationship Fields
-
I have an issue I’ve been wrestling with for several hours. I have a loop on my homepage, I originally was using a WP_Query, but changed it to a simpler get_posts foreach loop and am seeing the same issues. In the middle of the query I’m introducing a second query, for ACF Relationships. I tried all 3 examples from the ACF page, and managed to get most things working pretty well. Whats crazy now is that it’s pulling in the looped Relationships, it’s echoing the Title fine, and also an EDD Purchase Button, but I have one custom field that is not working. I tried grabbing it by get_field(‘name’), and by the_field(”), wp_post_meta(), echoing and not echoing and everything in between. Currently I’m using, the_field(‘sample’, $id) and it’s grabbing the URL I want correctly, but printing it outside of the anchor tag. If I use get_field(), it’s stays within the anchor tag, but uses the last variable of the group for all the instances? Even though, the title() and button are unique. Any suggestions would be awesome. Here is all my code between the header() and footer() PLEASE NOTE, the only kink with enough actual data is the first orangeish album cover with the face on it.
link to site:
https://szymanskimusic.com/newsite/link to github code:
https://github.com/szyam/szymanskimusic/blob/master/front-page.phpget_header(); ?> <header class="text-center padded"> <h4>albums / singles / discogrophy</h4> </header> <div class="rel-container"> <ul class="img-grid-4" id="releases"> <?php global $post; $args = array( 'post_type' => 'download', 'posts_per_page' => '-1', 'category_id' => array(2, 5, 4), 'order' => 'ASC' ); $custom_posts = get_posts($args); foreach($custom_posts as $post) : setup_postdata($post); ?> <li> <a class="hook" href="<?php the_permalink(); ?>"> <h5><?php the_title(); ?></h5> <?php if ( has_post_thumbnail() ) { the_post_thumbnail('full', array('class' => 'cover')); } ?> </a> <section class="info"> <h1><?php the_title(); ?></h1> <span class="close"><i class="icon-close"></i></span> <h6 class="price">Singles - $0.89 | Album - <?php echo get_post_meta( get_the_ID(), 'edd_price', true ); ?></h6> <?php // start second loop $temp_post = $post; // Storing the object temporarily //setup_postdata($post); $posts = get_field('szy_singles'); if( $posts ): ?> <ul class="tracks"> <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?> <?php //setup_postdata($post); $id = get_the_ID(); $sample = the_field( "sample", $id ); ?> <li> <a href="" data-src='<?php echo $sample; ?>' class="sm2_link"> <?php the_title(); ?> </a> <?php echo do_shortcode('[purchase_link class="button icon-cart" id="'. $id .'"]'); ?> </li> <?php endforeach; ?> </ul> <?php //wp_reset_postdata(); this reverts the post back to WP's sample post ?> <?php endif; ?> <?php $post = $temp_post; // Restore the value of $post to the original ?> <?php //end 2nd loop ?> <?php the_content(); ?> <?php echo do_shortcode('[purchase_link class="button"]'); ?> <footer class="entry-footer"> <?php szymanskimusic_entry_footer(); ?> </footer><!-- .entry-footer --> </section> </li> <?php endforeach; ?> </ul> <?php get_footer(); ?>
https://www.ads-software.com/plugins/advanced-custom-fields/
- The topic ‘Issues with Relationship Fields’ is closed to new replies.