WordPress.org

Ready to get started?Download WordPress

Forums

Types - Custom Fields and Custom Post Types Management
[resolved] $parent_post ?? (6 posts)

  1. Cristiano
    Member
    Posted 1 year ago #

    Hi friends,

    To get a child post of a custom post type, we can use this function:

    <?php echo $child_post->fields['my_field']; ?>

    What should I do if I want to get the parent post of some child? I tried this and it didnĀ“t work:

    <?php echo $parent_post->fields['my_field']; ?>

    Thanks!

    http://wordpress.org/extend/plugins/types/

  2. iana12
    Member
    Posted 1 year ago #

    I was looking for the same thing and found that

    wpcf_pr_post_get_belongs($post_id, $post_type)

    returns the id of the parent where $post_id is the id of the child post and $post_type is the type of post the parent is

  3. Matt Barrett (corradomatt)
    Member
    Posted 1 year ago #

    Thanks for this code iana12 but I'm having problems working out some details with a parent post field.

    I used the above code to find the post ID of the parent post and then I used the following code....
    <?php echo get_post_meta($parent_post,'wpcf-dob', true); ?>

    What I need is the date output from the dob field in the parent post but it's not displaying correctly. It gives me some numbers but unfortunately they in no way represent my date. Could someone point me in the right direction?

  4. brucepearson
    Member
    Plugin Author

    Posted 1 year ago #

    The date is stored as a unix timestamp. You can use the date function to display it how you want.

    `<?php
    $dob = get_post_meta($parent_post,'wpcf-dob', true);
    echo date("F j, Y", $dob);
    ?>

  5. Matt Barrett (corradomatt)
    Member
    Posted 1 year ago #

    Thanks Bruce! Worked great!!

  6. AmirHelzer
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for letting up know. I'll mark as resolved.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags