0

So basically I'm trying to run a loop of /downloads/ (using Easy Digital Downloads) on my homepage. I'm attaching custom fields to each album and trying to loop through that separately. This has been way more difficult than I imagined. I tried several different looping methods, some have worked better than others. My current solution is so close.

I've tried different resets, using and not using Global $post, I originally was trying to use the Relationship or Post Object field, which I'd still like to do. I swapped it for just straight custom field data thinking that would solve it but still not working.

I recently pasted the same code in the single-download.php and it worked fine. I adjusted the Reading settings in WP back and forth, reset permalinks. Really confused whats holding this code up on the homepage?

Here is my current code:

<ul class="img-grid-4" id="releases">

    <?php //global $post;
    $args = array(
        'post_type'        => 'download',
        'posts_per_page'   => -1,
        'cat'               => -8,
        'order'            => 'ASC',
        'paged' => ( get_query_var('page') ? get_query_var('page') : 1 ),
    );
    $custom_posts = new WP_Query($args);
    if ($custom_posts->have_posts()) :
        while( $custom_posts->have_posts()) :
            $custom_posts->the_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 if( have_rows('release_singles') ): ?>

        <ul class="tracks">
        <?php while( have_rows('release_singles') ): the_row(); 
            // vars
            $title = get_sub_field('title');
            $id = get_sub_field('cart_id');
            $link = get_sub_field('sample');
            ?>

            <li>
                <a href="" data-src="<?php echo $link; ?>" class="sm2_link">
                    <?php echo $title; ?>
                </a>
                <?php echo do_shortcode('[purchase_link class="button icon-cart" id="'. $id .'"]'); ?>       
            </li>

        <?php endwhile; ?>

        </ul>

    <?php endif; ?>



            <?php the_content(); ?>

            <a class="button" href="<?php the_permalink(); ?>">See Page</a>

            <?php echo do_shortcode('[purchase_link class="button"]'); ?>

            <footer class="entry-footer">
                <?php szymanskimusic_entry_footer(); ?>
            </footer><!-- .entry-footer -->
        </section>

    </li>

<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</ul>

Link to the demo site is here: http://szymanskimusic.com/newsite/

If you click on the first album (orange with face on it) a modal pops up with the album info, plus a list of the repeater fields. The title and Cart buttons are correct, but clicking on the song link loads and plays the same mp3 for each of the list items.

If you click the See Page button at the bottom, you'll go to the single page, which has the same loop, and is working fine.

Code is also here: https://github.com/szyam/szymanskimusic

front-page-2 is currently what I'm using, and methods-tried.php are the various loop's I've tried to use.

$('#releases > li').on('click', '.hook', function(e){
        var $this = $(this);

        $this.removeAttr('href').parent().addClass('live');

        var $list = $this.siblings('.info').find('li');
        $list.each( function(){
            var $src = $(this).children('.sm2_link').data('src');
            $('.sm2_link').attr( 'href', $src );
        })
        soundManager.reboot();
        e.preventDefault();
    });
szyam
  • 47
  • 7
  • Either that's not all of your code, or that's not your real code...When inspecting the source of your page, all links have the same `href` attribute defined. However, you've left it blank above. It's possible this is being done via JS. If so, you need to share that as well. – rnevius Oct 05 '15 at 16:07
  • It's not a ACF related question but rather about the plugin you use to playback the audio. Your "$link" variables have the correct value (inspect the source code). – xphan Oct 05 '15 at 16:09
  • Hey @rnevius , Im sorry I am doing that with JS. I guess I thought it was not part of the issue. My js for that is: $('#releases > li').on('click', '.hook', function(e){ var $this = $(this); $this.removeAttr('href').parent().addClass('live'); var $list = $this.siblings('.info').find('li'); $list.each( function(){ var $src = $(this).children('.sm2_link').data('src'); $('.sm2_link').attr( 'href', $src ); }) soundManager.reboot(); e.preventDefault(); }); ... I was trying to cut down loading the files on page load. – szyam Oct 05 '15 at 18:33
  • @xphan, I know I checked that on one of my earlier attempts? Good catch, I'm going to see if there is an issue with my jQuery. I dont think the issue is with SoundManager, since it's working fine on the single page. – szyam Oct 05 '15 at 18:36
  • jQuery inserted into original comment above. – szyam Oct 05 '15 at 18:41

0 Answers0