Toolset Types
[resolved] Problem with displaying Child Posts on Parent page (10 posts)

  1. Matt Barrett (corradomatt)
    Posted 3 years ago #

    I'm trying to display the child posts on a single CPT page and the output is very strange.

    I'm using the following code at the end of the post loop...

    				$child_posts = types_child_posts('puppies');
    				foreach ($child_posts as $child_post) {
    				  echo $child_post->post_title;
    				  echo $child_post->fields['color'];

    It works to display the post_title perfectly fine but it won't display the 'color' field value that I defined for the child posts. Instead it displays 'Array' and I'm not sure why it's doing this....any suggestions?

    Also, is there a way to display the child posts with html like we can for the Types Fields (aka 'output' => 'html')?


  2. Srdjan
    Posted 3 years ago #

    Can you try adding prefix 'wpcf-' if field is created with Types plugin?
    Is that field with multiple values or single value (non-repetitive field)?

  3. Matt Barrett (corradomatt)
    Posted 3 years ago #

    Thanks for the reply Srdjan. I changed the last line of code from above to...

    echo $child_post->fields['wpcf-color'];

    And now it doesn't output anything. The field is a 1 line text field, non-repetitive.

  4. Srdjan
    Posted 3 years ago #

    Can you create some debug output so we can see what is in there?

  5. Amir Helzer
    Plugin Author

    Posted 3 years ago #

    Let me try to help you by explaining what's happening. I hope that this will be enough to set you on the right course.

    types_child_posts will return the child posts, but you need to have the correct name of the custom field. It's explained, with an example here:

    Types custom fields are created with the wpcf- prefix by default. However, this may change if you associated an existing custom fields with Types control.

    You should approach this task in steps. First, see what the output from the types_child_posts call, as Srdjan suggested. Then, you can see how to display it.

  6. Matt Barrett (corradomatt)
    Posted 3 years ago #

    Thank you for your reply Srdjan and Amir. I used the print_r command to view the output as suggested and this is what is returned...

    Array ( [dob] => Array ( [0] => 1342310400 ) [eye-color] => Array ( [0] => ) [color] => Array ( [0] => Black/Brown Parti ) [pending] => Array ( ) [sex] => Array ( ) [date-available] => Array ( ) )

    I've looked through the code examples on that link and other pages throughout the wp-types website for help and I'm stumped. I'm not a php expert or anything but I can usually figure out issues like this....I'm just not having any luck this time.

  7. Matt Barrett (corradomatt)
    Posted 3 years ago #

    Ok, I got it. I was missing the [0] operator for the array to tell it what part of the resulting array I needed (even though there was only 1 option).

    So in my case, I want the "color" field on the post type I'm using so my code was this...
    echo $child_post->fields['color'];

    But should have been this...
    echo $child_post->fields['color'][0];

    Hopefully that will help out someone else in the future. Thanks again guys...btw, great plugin!

  8. waynmeyer
    Posted 3 years ago #

    corradomatt you truly are the man, thanx for this post u saved me so much time. really appreciate it :) i have one more question i think you can answer, how do i add a class and add

  9. views of the repeated fields?

    Any help will be greatly appreciated

  • waynmeyer
    Posted 3 years ago #

    Hey guys any help please? really need it ;)

  • Matt Barrett (corradomatt)
    Posted 3 years ago #

    Hi waynmeyer,

    I actually went a different route with my output. Here is some sample code that I used....

    Use this link to see the code.... http://pastie.org/6136066

    I hope that helps.

  • Topic Closed

    This topic has been closed to new replies.

    About this Plugin

    About this Topic


    No tags yet.