Support

Account

Home Forums ACF PRO Use Post Object to display info from another CPT

Helping

Use Post Object to display info from another CPT

  • Hi,
    I have two custom post types:
    Simulations and Faculty Resources and I want to display inside Faculty Resources posts information from the Simulations.
    I’ve created a Post Object inside the Faculty Resource post type with the field name: simulation_title_faculty that returns the Post ID.
    And I want to display the information on the front end using shortcodes because I use the Divi theme and this way it’s the best way to do it.
    Here’s the snippet I try to use without success:

    function md_about_f ($atts){
     $post_object = get_field('simulation_title_faculty');
      if( $post_object): 
     $md_about = get_field('about_this_lab',$post_object->ID); 
     $md_about = '<div>test' . $md_about . '</div>'; 
     wp_reset_postdata();
     return $md_about;
     endif;
    }
    add_shortcode( 'mdaboutsim', 'md_about_f' );
    

    What I do wrong?
    Thank you!

  • Your post object is alrwady set to return an ID, but you have $post_object->ID. Remove the ->ID and it should work.

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

The topic ‘Use Post Object to display info from another CPT’ is closed to new replies.