I'm using Advanced Custom Fields plugin and microkid Related Posts. I would like to display my custom fields inside Related post This is what I got so far?

<?php //related artworks

$related = MRP_get_related_posts( $post->ID, true, false, 'quote_list' );

//for testing related array
//print_r ($related);

if(!empty($related)) {
    foreach($related as $key => $value) {
        $related = get_post($value);
        echo "<div><h4>".get_the_title($related_id)."</h4></div>";
        //echo get_the_post_thumbnail($related_id);
        echo "".$related_content."<br/><br/>";
        echo "<a href=".get_permalink($related_id).">read more</a>";
        //for testing related array
        //print_r ($related);


But how I would pull out my advanced custom field? Many thanks,

2 Answers 2


According to advenced custom fields you get the value with get_field http://www.advancedcustomfields.com/docs/functions/get_field/

Just change "text_field" to your field-key.

$related = MRP_get_related_posts( $post->ID, true, false, 'quote_list' );

if( !empty( $related ) ) {
    foreach( $related as $key => $value ) { 

        // Get post
        $related = get_post( $value );

        // Get the field "text_field" on all posts
        $value = get_field( "text_field", $related->ID  );

        $output = '<div><h4>';
            $output .= get_the_title( $related->ID );
        $output .= '</div></h4>';

        // print the value from ACF

        if( $value ) {
            $output .= $value;

        $output .= $related->post_excerpt;

        $output .= '<a href="'. get_permalink( $related->ID  ) .'">'. __('Read more','domain') .'</a>';

    // Echo 
    echo $output;

Use the function get_post_meta() to get data to a custom field. Include this function in your loop and set the right parameters. The first parameter is the id of the post ($related_id) , the second is the key, the meta tags key/name, and the third parameter set to true, if you get a single parameters.

To get all meta data use get_post_custom($related_id).

For identifier the data and key can you use the plugin Debug Objects, but currently only the git version.https://github.com/bueltge/Debug-Objects

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.