'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;?>
i need to get the field of acf on my custom post type.
Solution 1:[1]
When getting field values outside the loop, you need to pass the id of the current object (Post, Term, User) as the second parameter to the functions get_the_field or the_field. Like so:
<?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 Documentation: https://www.advancedcustomfields.com/resources/the_field/
The same applies if you are using WordPress' inbuilt get_post_meta or get_user_meta, only you pass the id as the first parameter
https://developer.wordpress.org/reference/functions/get_post_meta/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tami |
