I have a question. I have a custom post type called Place. I have a situation that there can be place in place. I want to have a custom field parent_place where I could choose a parent of place.
The Place can have none or one parent.

Is there any posibility to list all posts (type = place) in custom field and choose one of them? In plugins for custom fields I can choose dropbox, radio, etc, but I have to type values. How can I automatically fill in a list of all posts which type is Place?

2 Answers 2


It depends on what plugin you are using to generate your custom fields.

For example the Advanced Custom Fields plugin has this option built in - the field type is called "Post Object".

ACF > Field Types > Post Object


ACF Post Object Options


As Michal Mau points out, ACF is easy and effective to automate this kind of Custom Field/Meta Box management.

The manual mode uses the action hooks add_meta_box and save_post. In this example, you'd have to adjust the indicated arrays to simply array( 'place' ). Check comments for details:

add_action( 'add_meta_boxes', 'add_custom_box_wpse_94701' );
add_action( 'save_post', 'save_postdata_wpse_94701', 10, 2 );

function add_custom_box_wpse_94701() 
    // Post types to insert the meta box. Adjust array <-------
    foreach( array( 'post', 'portfolio' ) as $pt )
            __( 'Custom parent' ), 

function blogroll_box_wpse_94701() 
    global $post, $typenow;

    // Get all posts of a type, excluding the current post
    $args = array(
        'numberposts' => -1,
        'post_type'   => $typenow,
        'post_status' => 'publish,future',
        'exclude'     => $post->ID,
    $get_posts = get_posts( $args );

    $saved = get_post_meta( $post->ID, 'custom_parent', true);

    // Security
    wp_nonce_field( plugin_basename( __FILE__ ), 'noncename_wpse_94701' );

    // Dropdown
    echo '<select name="custom_parent" id="custom_parent">
        <option value="">- Select -</option>';
    foreach ( $get_posts as $parent_post ) 
            '<option value="%d" %s> %s</option>',
            selected( $saved, $parent_post->ID, false),
    echo '</select>';

function save_postdata_wpse_94701( $post_id, $post_object ) 
    // Verify auto save 
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 

    // Security
    if ( 
        !isset( $_POST['noncename_wpse_94701'] ) 
        || !wp_verify_nonce( $_POST['noncename_wpse_94701'], plugin_basename( __FILE__ ) ) 

    // Allowed post types. Adjust array <-------
    $allowed_post_types = array( 'post', 'portfolio' );
    if ( !in_array( $post_object->post_type, $allowed_post_types ) )

    // Process post data
    if ( isset( $_POST['custom_parent'] )  )
        update_post_meta( $post_id, 'custom_parent', $_POST['custom_parent'] );
        delete_post_meta( $post_id, 'custom_parent' );

enter image description here enter image description here

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.