WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Can't retrieve custom field data with next post link (7 posts)

  1. Waqas
    Member
    Posted 1 year ago #

    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); ?>"/>';
    }
    ?>
  2. dfunkydog
    Member
    Posted 1 year ago #

    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); ?>"/>';
    }
  3. Waqas
    Member
    Posted 1 year ago #

    I tried this, but no result

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

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    echo '<img width="200" src="<?php echo get_post_meta($post->ID, 'label_value', true); ?>"/>';
  5. Waqas
    Member
    Posted 1 year ago #

    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.

  6. alchymyth
    Forum Moderator
    Posted 1 year ago #

    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.

  7. Waqas
    Member
    Posted 1 year ago #

    yeah, thanks

Topic Closed

This topic has been closed to new replies.

About this Topic