Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have two custom posts, one called "reviews" and another called "guides". I want to display a custom field from the post reviews if the title of the two matches.

Something like this: (I am not good with codes, this was the way I found to explain how I think it should be)

<? php
if ('$post_title' 'guides' == '$post_title' 'reviews') {
 echo ('custom_field' 'reviews');
 else
 return __(no details);
}
?>
share|improve this question

1 Answer 1

You don't mention exactly if you are referring to the default Custom Fields. If so, the solution bellow doesn't apply.

But, much better than the default, is to create a Custom Meta Box where you present your Custom Field(s).

The Codex has an example in Function_Reference/add_meta_box.
These can also be useful:

Check the comments in the code and also the message that's printed in the MB.

add_action( 'add_meta_boxes', 'add_meta_box_wpse_75963' );

function add_meta_box_wpse_75963() 
{
    // This prevents the code from going further if not in the correct post type
    global $post;
    if( 'reviews' != $post->post_type )
        return;

    // Check if the other post type has a post with the same title
    // If it doesn't, bail out
    $other_page = get_page_by_title( $post->post_title, OBJECT, 'guides' );
    if( !$other_page )
        return;

    // We are in the correct post_type (reviews)
    // and there is another post in "guides" with the same title
    add_meta_box(
        'wpse_42440_sectionid',
        __( 'Custom Field' ), 
        'display_meta_box_wpse_75963',
        'reviews'
    );
}

function display_meta_box_wpse_75963() 
{ 
    echo "Insert custom field procedures here.";
    echo "Also create the appropriate <code>add_action( 'save_post', 'callback');</code>";
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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