Title: get_post_custom_values
Last modified: August 19, 2016

---

# get_post_custom_values

 *  [lobos55](https://wordpress.org/support/users/lobos55/)
 * (@lobos55)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/get_post_custom_values/)
 * 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](https://wordpress.org/support/users/lobos55/)
 * (@lobos55)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/get_post_custom_values/#post-1046155)
 * 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](https://wordpress.org/support/users/lobos55/)
 * (@lobos55)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/get_post_custom_values/#post-1046173)
 * 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](https://wordpress.org/support/users/lobos55/)
 * (@lobos55)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/get_post_custom_values/#post-1046188)
 * 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](https://wordpress.org/support/users/lobos55/)
 * (@lobos55)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/get_post_custom_values/#post-1046200)
 * can be closed

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘get_post_custom_values’ is closed to new replies.

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)

 * 4 replies
 * 1 participant
 * Last reply from: [lobos55](https://wordpress.org/support/users/lobos55/)
 * Last activity: [16 years, 12 months ago](https://wordpress.org/support/topic/get_post_custom_values/#post-1046200)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
