How to get attached file in wordpress from custom post

I am using the Download monitor plugin

I am listing the posts by category the following way

Read More
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 

<?php

            $args = array(
                'post_type' => 'dlm_download',
                'posts_per_page' =>25,
                'numberposts' => null,
                'dlm_download_category' => $term->slug
            );

                $downloads = get_posts($args);

                foreach ($downloads as $download) {

                    echo '<div class="download-content">';

                        echo '<h3>
                                <a href="" title="Letöltés"><i class="left icon-arrow-down"></i></a>
                                '.$download->post_title.' 
                                <a href="" title="Információ"><i class="right icon-plus"></i></a>
                            </h3>'; 

                        echo '<p>'.$download->post_excerpt.'</p>';

                    echo '</div>';
                }


        ?>

But i have no idea how to show custom post attached file. The file is contained i the wp_postmeta table,

I tryed with wp_get_attached_ur($download->ID) but it returns an empty string

Anybodycould please give me a hint?

Related posts

1 comment

  1. Using the Download monitor Plugin, you can not access the File directly via URL, as the plugin restricts the access to the download monitor Folder.

    You can generate the downloadlinks quite easily, and still use the plugins counter and other methods.

    If you pass the ID of the download as a $_GET-variable to your WordPress installation, the plugin will handle the rest itself:

    $downurl = get_bloginfo( 'url' )  . '?download=' . $download->ID;
    

    Resulting in a link like http://example.com?download=1234.

    The reason you could not get the download URL by using wp_get_attached_url() is that the dlm_download that you loop through is just a Custom Post Type, and not an attachment by itself. The attachment is connected to the downloadCPT by the post_parent. This way the plugin knows, which download to deliver with which request.

    Your code could look something like that:

    $args = array(
        'post_type' => 'dlm_download',
        'posts_per_page' => 25,
        'numberposts' => null,
        'dlm_download_category' => $term->slug
    );
    
    $downloads = get_posts($args);
    
    foreach ($downloads as $download) {
    
        echo '<div class="download-content">';
    
            echo '<h3>
                <a href="' . get_bloginfo( 'url' )  . '?download=' . $download->ID . '" title="Letöltés">
                    <i class="left icon-arrow-down"></i>
                    '.$download->post_title.'
                </a>
                <a href="' . get_bloginfo( 'url' )  . '?download=' . $download->ID . '" title="Információ">
                    <i class="right icon-plus"></i>
                </a>
            </h3>'; 
    
            echo '<p>'.$download->post_excerpt.'</p>';
    
        echo '</div>';
    }
    

    However, you could also use the Plugin’s built in methods to achieve quite the same thing.

Comments are closed.