Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4726
    zibi zibi
    Participant

    Hi, I have a Custom Post Type called “brand”. I’m displaying all instances of it with a WP_Query() loop. I’d like to display attachments of each too, however the manual shortcode call (echo do_shortcode(“[download-attachments]”); ) doesn’t display anything. Here’s my code:

    $query_brands = new WP_Query('post_type=brand');
    while ($query_brands->have_posts()) : $query_brands->the_post();
    	the_title();
    	echo do_shortcode("[download-attachments]"); 
    endwhile;

    Why do attachments not appear?

    #4727
    Bartosz
    Keymaster

    Hello Zibi,

    It doesn’t work because the shortcode does not allow you to pass post_id as an argument. It would be required here.

    But there’s a much better and flexible method for this case, just use the da_display_download_attachments() function:

    $query_brands = new WP_Query('post_type=brand');
    
    // optional arguments
    $args = array(
    	'container' => 'div',
    	'container_class' => 'download-attachments',
    	'container_id' => '',
    	'style' => 'list',
    	'link_before' => '',
    	'link_after' => '',
    	'display_user' => true,
    	'display_icon' => true,
    	'display_count' => true,
    	'display_size' => true,
    	'display_date' => true,
    	'display_caption' => true,
    	'display_description' => true,
    	'display_empty' => 0,
    	'display_option_none' => __('No attachments to download', 'download-attachments'),
    	'use_desc_for_title' => 0,
    	'exclude' => '',
    	'include' => '',
    	'title' => __('Download Attachments', 'download-attachments'),
    	'orderby' => 'menu_order',
    	'order' => 'asc',
    	'echo' => 1 // 1 for echo or 0 for return
    );
    
    while ($query_brands->have_posts()) : $query_brands->the_post();
    	the_title();
    	// echo the attachments
    	da_display_download_attachments($post->ID, $args);
    endwhile;

    Of course you don’t have to use the $args and rely on what you have set in the plugin settings. Then use:

    da_display_download_attachments($post->ID);

    #4862
    zibi zibi
    Participant

    Works fine, thanks !

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.