How to get_field() in posts loop in WordPress?

I am trying to create a function for a shortcode to loop through an ‘articles’ custom post type. This is essentially a downloadable file uploaded by users and is a custom post type without the content field/editor box in the post editor. This custom post type also has a ‘download_link’ ACF field attached to it which is the location of the file for downloads. This is the href attribute for each post in the feed. However, the field is not generating any output in the function below. However the title is being populated. I know that all the article posts have a value provided for this particular field. Am I missing something? Thanks.

function articles_download_feed(){
$articles_query = new WP_Query(array(‘post_type’ => ‘article’,
‘post_status’ => ‘any’));
if( $articles_query->have_posts() ){
$output = ‘<ul>’;
while( $articles_query->have_posts() ){
$articleID = get_the_ID();
$title = get_the_title($articleID);
if(get_field(‘download_link’, $articleID)){
$download = get_field(‘download_link’, $articleID, true);
} else {
$download = ‘ABC’;
$output .= ‘<li><a target=”_blank” href=”‘.$download.'”>’.$title.'</a></li>’;
$output .= ‘</ul>’;
return $output;
} add_shortcode(‘articles_feed’, ‘articles_download_feed’);

Read more here:: How to get_field() in posts loop in WordPress?

Leave a Reply

Your email address will not be published. Required fields are marked *