Home Forums General Issues ACF, CPT and Genesis – Trouble accessing Post Object


ACF, CPT and Genesis – Trouble accessing Post Object

  • Hi Everyone,

    I’m hoping someone here can help, as I’ve tried the Genesis forums to no avail.

    I am using a Genesis Child Theme, and have installed the Custom Post Types and Advanced Custom Field plugins to create new Post Types.

    I have created the following Custom Post Types:
    – xxx_staff
    – xxx_location

    I have created the following Custom Fields
    – Staff
    Field Name Field Type
    name Text
    location Post Object ( with Post Type -> xxx_location )
    email Email
    Description Wysiwyg Editor

    Location Rules
    Show this field group if “Post Type” “is equal to” “xxx_staff”

    – Location
    Field Name Field Type
    label Text
    map Google Map
    logo Image
    phone_number Text

    Location Rules
    Show this field group if “Post Type” “is equal to” “xxx_location”

    I am in the single-xxx_staff.php code, and trying to pull all elements out of the Staff Object. I’m following the code example here:

    And all elements are accessed successfully, except the location Post Type.

    The location post object doesn’t seem to get populated into the global post object. And when you call the_title(); the title of the parent (staff) post object is returned. Here is my code:

    remove_action( 'genesis_entry_content', 'genesis_do_post_content');
    add_action('genesis_entry_content', 'ladc_do_post_content');
    function ladc_do_post_content() {
        	<h3><a href="<?php the_permalink(); ?>">Staff Title: <?php the_title(); ?></a></h3>
        	<p>Staff Name: <?php echo get_field('name'); ?></p>
    	$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>
    	    <?php wp_reset_postdata(); ?>
    	<?php endif; ?>

    Playing a little more, I removed all ‘Genesis’ Code and just ran the rest of the code, and was able to access the child ‘location’ post object successfully.

    So this leads me to think there is something funky happening when ACF and Genesis play together.

    While this may not necessarily be an ACF bug, I was hoping that someone here has had a similar experience, and knew of a work around. If I can’t find a solution, I may have to revert to uninstalling ACF and doing it the old fashion way (which would be sad, because this is an awesome product!).

  • Oh. To add one more piece of information.

    I am able to see the location array that is returned and it has all the information i need in it. So at a pinch, I can iterate through that array to get the datapoints I need. Just odd that the setup_postdata( $post ); call doesn’t seem to work when run through genesis.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.