Title: Basic get_post_meta call outside loop?
Last modified: August 19, 2016

---

# Basic get_post_meta call outside loop?

 *  [saloonstudios](https://wordpress.org/support/users/saloonstudios/)
 * (@saloonstudios)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/basic-get_post_meta-call-outside-loop/)
 * I’ve tried several code snippets and they either don’t work for me or I’m not
   using them correctly-
    Situation is this, I’ve set up a small block for a sidebar
   that recalls custom fields from a specified post ID. Within the loop it works
   flawlessly. A sample of that from my sidebar.php is here:
 *     ```
       <?php 	$featuredOne = 342;
       		$featuredTwo = 155; ?>
   
       		<ul><li><a href="<?php echo get_permalink($featuredOne) ?>"><?php echo get_post_meta($featuredOne, short_name, true) ?></a>
       ```
   
 * That’s just a piece but you get the idea. What I want to do now is make a new
   php file that run that snippet and spits out the html so I can @readfile that
   php on another website.
    I’m assuming I need to use some variation of $wp_query
   to get the meta out of the loop but I don’t know what code to use and I don’t
   know where this new php file will need to live in my directory structure relative
   to my wordpress install.
 * Hopefully this makes sense,
    Thanks-

Viewing 1 replies (of 1 total)

 *  Thread Starter [saloonstudios](https://wordpress.org/support/users/saloonstudios/)
 * (@saloonstudios)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/basic-get_post_meta-call-outside-loop/#post-1597935)
 * Ah success. I guess what I meant wasn’t “outside the loop” but actually “outside
   the framework. I found the code I was missing:
 *     ```
       require_once('../../../../wp-load.php');
       require_once('../../../../wp-includes/post.php');
       ```
   
 * This seems to work. Is there a security risk in loading the php data and @readfile’ing
   it onto another page in this manner?

Viewing 1 replies (of 1 total)

The topic ‘Basic get_post_meta call outside loop?’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [saloonstudios](https://wordpress.org/support/users/saloonstudios/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/basic-get_post_meta-call-outside-loop/#post-1597935)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
