WordPress.org

Ready to get started?Download WordPress

Forums

reset post id (3 posts)

  1. lobos55
    Member
    Posted 5 years ago #

    When using the following code:

    <?php $news = get_post_meta($post->ID, 'Related news', false); ?>
    <?php if($news) : ?>
    <h3>Related news</h3>
    <?php foreach ($news as $new) : ?>
    <?php $my_query = new WP_Query("p=$new");
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <b><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></b>
    <?php endwhile; ?>
    <?php endforeach; ?>
    <?php endif; ?>

    the id of the last ($my_query->have_posts()) : $my_query->the_post(); is being retained. How can I reset id back to current post?

  2. vijayrajesh
    Member
    Posted 4 years ago #

    hey you got the solution. I am having similar problem.

  3. vijayrajesh
    Member
    Posted 4 years ago #

    yes, i fixed it.

    in the beginning of page, i remembered the current post variable to some variable.

    So whenever needed, i used that variable.

Topic Closed

This topic has been closed to new replies.

About this Topic