WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom FlexSlider script not displaying links properly (2 posts)

  1. wspencer
    Member
    Posted 2 years ago #

    I'm creating a custom plugin that utilizes the FlexSlider jQuery plugin to display a slideshow of a custom post type. However, I've run into a snag. Either something is hard-wired in the js that I'm missing or I'm doing something wrong on my end.

    Here is the loop the fills the slideshow....

    function efs_get_slider(){  
    
        $slider= '<div class="flexslider">
              <ul class="slides">';  
    
            $efs_query= "post_type=events";
            query_posts($efs_query);  
    
            if (have_posts()) : while (have_posts()) : the_post();
                $img= get_the_post_thumbnail( $post->ID, 'large' );
    			$link= esc_url (get_post_meta( $post->ID, '_link', true ));
    
     			$slider.='
    
    <li><a href="' .$link. '">' .$img. '</a></li>
    ';
    
     		endwhile; endif; wp_reset_query();  
    
            $slider.= '
            </div>';  
    
            return $slider;
    
    }

    The issue comes with the $link variable. I have a custom meta field for my custom post type that just holds an external link. I'm thinking it has something to do with my loop and not the js file because when I manually put a link into the code, the links show up fine in the slideshow.

    However, I ran the same query on a test page without using the slideshow and it seems to work fine.

    I've done this with and without the esc_url function and have the same results. I can provide the js file so you can see the code, too.

    A working test page of the slider can be found at the address below. Below the slideshow is the output of the same query_posts loop but not using the slideshow.

    http://www.curemyway.com/test-page

    I'm at a loss here. Any help is greatly appreciated.

  2. wspencer
    Member
    Posted 2 years ago #

    After much digging around in the Codex, I figured it out. Turns out that I needed to restructure how I was calling the post->ID in the get_post_meta call....

    Old....

    $link= get_post_meta( $post->ID, '_link', true);

    The way that works with FlexSlider.....

    $id = get_the_ID();
    $link= get_post_meta( $id, '_link', true );

    I'd love to see an explanation as to why this works but I'm just happy that it works!

Topic Closed

This topic has been closed to new replies.

About this Topic