WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Field Isn't Displaying (6 posts)

  1. mattblank
    Member
    Posted 2 years ago #

    Hi,

    In my footer I use this code:

    <?php
    $posts = get_posts('cat=5&numberposts=3');
    foreach ($posts as $post) : start_wp(); ?>
    <li><a href="<?php the_permalink(); ?>">
    <?php the_post_thumbnail('thumbnail'); ?>
    <?php
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'Short Teaser', true);
    ?></a></li>
    <?php
    endforeach;
    ?>

    Notice after the thumbnail, I'm pulling in a custom field called Short Teaser. This works on every page (though I've had previous issues). But on one of my category pages changing:

    <?php if ( have_posts() ) : ?>

    to

    <?php if ( have_posts() ) : query_posts($query_string."&posts_per_page=2&paged=$paged"); ?>

    By doing this, it means on this page it prevents the custom field from showing (thumbnail still displays). Anyone know how I can avoid this? I presume I can pull in the custom field in some other way to stop avoid the clashes I keep getting at every corner.

    Thanks!
    Matt

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Try:

    <?php query_posts($query_string."&posts_per_page=2&paged=$paged");
    if ( have_posts() ) :  ?>
  3. mattblank
    Member
    Posted 2 years ago #

    Thanks Esmi, but alas that doesn't work. It still makes the custom fields disappear.

    I've had such issues with the custom field code :( So many things clash with it.

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    Are you resetting the query after your main Loop & before the secondary Loop?

  5. mattblank
    Member
    Posted 2 years ago #

    Perfect!!

    You are my new hero! It's been bugging me for days :)

    A thousand thanks Esmi.

    Matt
    xx

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    No problem :-)

Topic Closed

This topic has been closed to new replies.

About this Topic