• I have a post containing custom field “Related news”, which has the ID of a related post, like “Related news”=”1234”. Each post has multiple values of this field. I want to use that value to retrieve the title of the related post:

    <?php $news = get_post_custom_values(‘Related news’);
    foreach ( $news as $key => $value ) {

    <?php $my_query = new WP_Query(“p=$value”);
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><b>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”>
    <?php the_title(); ?>
    </b>
    <?php endwhile; ?>
    }
    ?>

    Apparently there is a mistake in it, as it returns a blank page.
    Where is the mistake?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter lobos55

    (@lobos55)

    Sorry, mistake in cut and paste

    <?php $news = get_post_custom_values('Related news');
      foreach ( $news as $key => $value ) {
    <?php $my_query = new WP_Query("p=$value");
    	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; ?>
      }
    ?>

    PS using 2.7.1

    Thread Starter lobos55

    (@lobos55)

    This works, but only renders the first value:

    <?php $news = get_post_meta($post->ID, 'Related news', true); ?>
    <?php $my_query = new WP_Query("p=$news");
    	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; ?>
    Thread Starter lobos55

    (@lobos55)

    Tried this one, but also renders just the first one.

    <?php $news = get_post_meta($post->ID, 'Related news', false); ?>
    <?php foreach ($news as $new) : ?>
    $post = get_posts('id=$new');
    <b><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title();? ></a>	</b>
    <?php endwhile; ?>
    <?php endif; ?>
    </div>
    <?php endforeach; ?>
    Thread Starter lobos55

    (@lobos55)

    can be closed

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_post_custom_values’ is closed to new replies.