• Resolved muhammadwaqas

    (@muhammadwaqas)


    Hello,

    I’m trying to use conditional tag with next post link. I want to get data from custom field but its not showing up. the if condition is working but the piece of code im using to get filed data is not working. below is my code

    this part isn’t working <?php echo get_post_meta($nextPost->ID, 'label_value', true); ?>

    <?php
                    wp_reset_postdata();
                } //end foreach
            } // end if
            $nextPost = get_next_post();
            if($nextPost) {
                $args = array(
                    'posts_per_page' => 1,
                    'include' => $nextPost->ID
                );
                $nextPost = get_posts($args);
                foreach ($nextPost as $post) {
                    setup_postdata($post);
        ?>  
    
                <a href="<?php the_permalink(); ?>">
                <p><?php the_title(); ?> »</p>
    <?php
    // Must be inside a loop.
    
    if ( has_post_thumbnail() ) {
    	the_post_thumbnail('thumbnail');
    }
    else {
    	echo '<img width="200" src="<?php echo get_post_meta($nextPost->ID, 'label_value', true); ?>"/>';
    }
    ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • Didn’t check the logic but surely this line has syntax errors

    else {
    	echo '<img width="200" src="<?php echo get_post_meta($nextPost->ID, 'label_value', true); ?>"/>';
    }
    Thread Starter muhammadwaqas

    (@muhammadwaqas)

    I tried this, but no result

    echo '<img width="200" src="'.get_post_meta($nextPost->ID,'label_value',ture).'_250.jpg"/>';

    echo '<img width="200" src="<?php echo get_post_meta($post->ID, 'label_value', true); ?>"/>';
    Thread Starter muhammadwaqas

    (@muhammadwaqas)

    this code is working. I just remove the “next” from post id.

    alchymyth code seems correct too but it doesn’t work that way. But I’ve got the idea that I was wrong about $nextPost->ID

    echo ‘<img src=”‘.get_post_meta($post->ID,’label_value’,ture).'”/>’;

    Thanks all.

    well spotted 😉

    – I missed that because I just focussed on the $post_ID and your queston did not mention any syntax errors.

    if this is all, please mark the topic as ‘resolved’ – dropdown at the right or tick box near the bottom.

    Thread Starter muhammadwaqas

    (@muhammadwaqas)

    yeah, thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Can't retrieve custom field data with next post link’ is closed to new replies.