lobos55
Member
Posted 3 years ago #
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?
lobos55
Member
Posted 3 years ago #
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
lobos55
Member
Posted 3 years ago #
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; ?>
lobos55
Member
Posted 3 years ago #
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; ?>
lobos55
Member
Posted 3 years ago #