最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ACF Pro Accessing fields on a Custom Post Type

programmeradmin0浏览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.

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.

Share Improve this question asked Nov 6, 2019 at 3:54 David--David-- 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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 ?>')">
发布评论

评论列表(0)

  1. 暂无评论