How can php be used to the return data from a custom field in a post?

Any help would be greatly appreciated.

2 Answers 2


If you want to use php inside the Post Content editing interface, it will not work (for security reasons), unless you install a plugin that allows it.

If you mean that the php would be put in the template file, then you can use the functions the_meta();(doc) and the more flexible get_post_meta($post_id, $key, $single);.


I set something like this up by creating a template page and uploading via ftp. The gist of the coding using Advanced Custom Fields worked using the following in the editor:

<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>


$posts = get_posts(array(
    'posts_per_page'    => -1,
'post_type'         => 'post',
'category_name' => 'all-properties'

if( $posts ): ?>

<?php foreach( $posts as $post ): 

    setup_postdata( $post );


<?php the_post_thumbnail( 'small' ); ?><br>
        <b><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></b><br>
        <?php the_field('short_description'); ?><br>

<?php endforeach; ?>

<?php wp_reset_postdata(); ?>

Let me know if this is what you are looking for and if I can help with any further information. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.