Home Forums Front-end Issues Problem with 'file' URL output.


Problem with 'file' URL output.

  • Hello,

    I have added a ‘file’ custom field to the regular post type. Now I want to loop through every post and output a Link with the URL of the file on a page.

    This is what I have at the moment:

    add_shortcode( 'qg_shortcode', 'qg_shortcode' );
    function qg_shortcode() {
    	global $post;
    	$link = get_field('datenpacket');
        $buffer = '<h3>Datenpakete</h3>';
        $q = new WP_Query(array(
            'post_type' => 'post',
            'posts_per_page' => 5
        while ($q->have_posts()) {
        	$buffer = $buffer . "<a href='" . the_field('datenpacket') . "'>" . 'TEST' . '</a>' . '</br>';
        return $buffer;

    The problem is, that the output is wrong. The Links are created, but not with the right href, instead the file urls are displayed on top of the page.

    Any ideas?

  • Try using the $link variable in place of the_field('datenpacket') – this will use get_field('datenpacket') instead which should create the proper href.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.