0

I'm an intermediate PHP user and I've been able to do some great things on my own with ACF but I could use some help. Instead of using an options page, I would like to add some fields to the Custom Post Type I've created -> Team Members. For now I would just like have an image field that will be used on the archive page. I will be using the Archive page archive-team_members to display all the members. I'm having trouble pulling this image field into the archive template. I'm not sure how to specify the top level of Team Members as the source of the field. Using this page as reference I attempted to use the following, but the image url displays empty.

<?php 
        $term = get_queried_object();

        $image = get_field('team_members_page_image', $term);

        ?>
<div class="post-hero-image archive-header" style="background-image: url('<?php echo $image ?>')">

Can anyone lead me in the right direction here? Or is making a Team Members Option page the best way to go about doing this. Thank you very much.

example

0

Try this code

<?php  $image = get_field('team_members_page_image', 'option');  ?>
<div class="post-hero-image archive-header" style="background-image: url('<?php echo $image ?>')">
  • I have tried that, but since the top level post type page is not an Option page, it doesn't know where that field is. I think my three options are.. create an Options page, use a normal page template to mimic the archive page, or find a way to use the one above. I'm not sure why ACF would make it an option to add fields to a top level post type if they can't be used. – David-- Nov 6 '19 at 6:24
  • Ok, how did you create this options page, a screenshot of which is in your question? – user28956 Nov 6 '19 at 6:31
  • If you have not created any options page yet and the screenshot is just for example, then try using this plugin ru.wordpress.org/plugins/acf-cpt-options-pages – user28956 Nov 6 '19 at 6:40
  • I know how to create an options page, I was just trying to avoid it by putting the field on the post type instead. That screenshot is the top level of the post type with the custom image field assigned to it. – David-- Nov 6 '19 at 7:09
  • Try this plugin wordpress.org/plugins/acf-cpt-options-pages – user28956 Nov 6 '19 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.