Forum Replies Created
-
AuthorPosts
-
kristieMember
Hey Porter.
I have posted on the ACF forum as well. I'll see what comes back there.
You would think I'd tried echoing out the attributes, but I don't think I had, so thanks for the tip! The location attribute (ie, child custom post type) is returned as an array. And it has all the data in it! So worst case now comes down to me iterating through that array to get the datapoints I need.
I think there is something funky going on with Genesis and the setup_postdata( $post ) method. As mentioned, when I remove all the genesis stuff, the code works perfectly. So I'll move ahead with iterating through the array, as I think that's going to be the most viable solution for now.
Thank you!
kristieMemberThanks Dave. It is a strange one, and one quite specific to Advance Custom Fields Plugin. I'm hoping that someone else has experienced the same thing and has some advice, rather than someone to fix it for me. I'm also open to advice on the best practices around creating custom post types and using Genesis. Is there another Plugin people would recommend? Worst case I go back and remove the plugin and build them from scratch.
kristieMemberThanks Porter! I will definitely bookmark this code to help me in future, but I don't think it's quite the problem I'm having right now.
I have a Custom Post type (Staff) that has another Post Type (Location, also custom) as an attribute. While I can access the parent Post type I'm unable to get the attributes in the child Post Type, using the sample code that ACF provides.
It would be closer if instead of a text city field on your Page, you assigned a 'location' Custom Post Type, which would then contain information such as city, etc. I'm getting all the parent attributes OK, but can't access the child Post Type attributes within it.
Staff Custom Field
- Name (text)
- Position (text)
- Location (Post Type) --> Location Custom FieldLocation Custom Field
- Map (Google Map)
- Logo (Image)
- Phone Number (text)If accessing the Location Custom Field independently, I can access all elements. Only when I access it as a child custom field from Staff, does it not behave as expected.
I hope this adds some clarity.
kristieMemberThank you for your response David. You are spot on. I am quite used to the standard WP style, and the Genesis templates do look funny 🙂 So bear with me.
I took a look a the examples you posted, and couldn't quite adjust them to fit my problem, so I'm not sure if I'm not doing something right, or if I'm not explaining my problem clearly enough.
I'm able to successfully pull data out of the Post type, except for when the field returns a Post Object.
The page this code is going on is for a single Post Item (i.e. One Staff Member). Within that Single post item, is a relationship to another Custom Post type, Location, which could contain multiple posts. (NOTE: I also tried this with a Single Post Type as the "Field Type", therefore removing any need for a loop and the same problem occurs).
I am able to access all the other fields from the Staff object, without a problem.
Let me try a different angle on the problem. I have made some adjustments to the setup and code, so instead of defining a Custom Field Type Group with the field set to "Relationship, which could have multiple Post Types attached, I have changed it to be a Field Type of "Post Object" so only one is returned.
New code:
remove_action( 'genesis_entry_content', 'genesis_do_post_content'); add_action('genesis_entry_content', 'ladc_do_post_content'); function ladc_do_post_content() { ?> <div> <h3><a href="<?php the_permalink(); ?>">Staff Title: <?php the_title(); ?></a></h3> <p>Staff Description: <?php echo get_field('description'); ?></p> <?php $post_object = get_field('location'); if( $post_object ): // override $post $post = $post_object; setup_postdata( $post ); ?> <h3><a href="<?php the_permalink(); ?>">Location Title: <?php the_title(); ?></a></h3> <p>Location Phone Number: <?php the_field('phone_number'); ?></p> </div> <?php wp_reset_postdata(); ?> <?php endif; ?> <?php } genesis();
The code to access the Location Post Object from the parent Staff object was pulled from here: http://www.advancedcustomfields.com/resources/field-types/post-object/
The result of this code displays the Staff Title and Description, as expected, but when displaying the Location object fields, it displays the title of the parent object (Staff) again and nothing for the field "phone_number" as it is only a valid field for the Location object, not for the Staff object. If I replaced that field with a valid Staff field, it would return successfully.
So it seems that the ACF sample code to access the Post Object and call the setup_postdata() on it, does not work when running through the Genesis engine, and therefore the original Staff Object is not being overwritten.
I hope this helps clarify the issue. Please let me know if I can provide any further information.
Cheers, Kristie
-
AuthorPosts