0
votes

I've created a custom posts called Projects and created a Projects template inside of archive-projects.php. I've also created a single-projects.php to display individual project. However, this became a problem when I had to use an ACF on the Projects template. I want to display a featured project on the Project page and also list out few of the posts I've created for projects on the same page. Below is my code to get featured project image.

<?php echo get_field('featured_project'); ?>


<?php
    $featured_project = get_field('featured_project');
    if ($featured_project):

        $project = $featured_project;
        setup_postdata( $project );

        if ( has_post_thumbnail($featured_project->ID) ) { // check if the post has a Post Thumbnail assigned to it.
        $featured_image = wp_get_attachment_image_src( get_post_thumbnail_id($featured_project->ID), 'large' );
        $featured_image = $featured_image[0];
    } 

?>

I've read few articles and similar questions on Stackoverflow but haven't found an answer yet. Has anyone been successful figuring this out?

1
So projects are also posts, right? did u assign the projects category to those posts? - Maha Dev
what is the acf field , checkbox, selectbox or Yes/No option?? - Prakash Rao
@MahaDev Dev Projects are also Posts. Projects have categories named Services and Technologies. - Kaya Kim
@PrakashRao The acf field is Post Object. User will have a choice to grab a post filtered by post type 'Project' - Kaya Kim

1 Answers

0
votes

You can try to use my plugin ACF CPT Options Page

That creates options page for each custom post type, then you can add Relationship Field to get posts easily