我需要在高级自定义字段上获取自定义 post 类型的字段
I need to get the field of custom post type on advance custom field
<?php $series = get_field('series'); ?>
<?php foreach($series as $series):?>
<a href="<?php echo get_page_link($series->ID);?>">
<img src="<?php echo get_the_post_thumbnail_url($series->ID, 'thumbnail');?> ">
<h3><?php echo $series->post_title;?></h3>
<!-- <?php the_field('series_details');?> This is the field that i want to pull out -->
</a>
<?php endforeach;?>
我需要在我的自定义 post 类型上获取 acf 字段。
在循环外获取字段值时,需要将当前对象(Post、Term、User)的id作为第二个参数传递给函数get_the_field或the_field.像这样:
<?php $series = get_field('series'); ?>
<?php foreach($series as $series): ?>
<a href="<?php echo get_page_link($series->ID);?>">
<img src="<?php echo get_the_post_thumbnail_url($series->ID, 'thumbnail'); ?> ">
<h3><?php echo $series->post_title;?></h3>
<?php the_field('series_details', $series->ID); ?> <!-- This is the field that i want to pull out -->
</a>
<?php endforeach; ?>
ACF 文档:https://www.advancedcustomfields.com/resources/the_field/
如果您使用 WordPress 的内置 get_post_meta 或 get_user_meta,同样适用,只是您将 id 作为第一个参数传递
https://developer.wordpress.org/reference/functions/get_post_meta/
<?php $series = get_field('series'); ?>
<?php foreach($series as $series):?>
<a href="<?php echo get_page_link($series->ID);?>">
<img src="<?php echo get_the_post_thumbnail_url($series->ID, 'thumbnail');?> ">
<h3><?php echo $series->post_title;?></h3>
<!-- <?php the_field('series_details');?> This is the field that i want to pull out -->
</a>
<?php endforeach;?>
我需要在我的自定义 post 类型上获取 acf 字段。
在循环外获取字段值时,需要将当前对象(Post、Term、User)的id作为第二个参数传递给函数get_the_field或the_field.像这样:
<?php $series = get_field('series'); ?>
<?php foreach($series as $series): ?>
<a href="<?php echo get_page_link($series->ID);?>">
<img src="<?php echo get_the_post_thumbnail_url($series->ID, 'thumbnail'); ?> ">
<h3><?php echo $series->post_title;?></h3>
<?php the_field('series_details', $series->ID); ?> <!-- This is the field that i want to pull out -->
</a>
<?php endforeach; ?>
ACF 文档:https://www.advancedcustomfields.com/resources/the_field/
如果您使用 WordPress 的内置 get_post_meta 或 get_user_meta,同样适用,只是您将 id 作为第一个参数传递
https://developer.wordpress.org/reference/functions/get_post_meta/