siaeva
siaeva

Reputation: 164

Correct php formatting for dynamic link text

I'm trying to use a dynamic field in Wordpress (using custom fields) to generate some link text. However the formatting I am using is certainly wrong as it just prints the words on the page without including them within the link. It's the last line (beginning with echo) that is incorrect. Any ideas, folks?

<?php
        $args = array( 'numberposts' => '1', 'category' => CAT_ID );
        $recent_posts = wp_get_recent_posts( $args );
        foreach( $recent_posts as $recent ){
        echo '<h3 id="latest"><a href="' . get_permalink($recent["ID"]) . '">' . the_field('report_text') . '</a></h3>';
        }
    ?>

Upvotes: 0

Views: 28

Answers (1)

michaelmcgurk
michaelmcgurk

Reputation: 6509

the_field('report_text') should be get_field('report_text')

Upvotes: 1

Related Questions