Querying Post-Type: Attachmanet

Hey there,

not sure if this is a real bug or a “feature request”, so please feel free to change the category if it doesn’t fit here.

I’m trying to solve a problem with a Query (post-type: attachment) I want to use. Basically I want to create a downloadable “Brand Assets” Section where I have a preview of an image and the title, and on clicking the image I can download it.

However I have problems with outputting the images inside the query-block. The following is my query:

// The Arguments
$args = array (
  'post_type' => 
  array (
    0 => 'attachment',
  'post_status' => 
  array (
    0 => 'inherit',
  'ignore_sticky_posts' => true,
  'tax_query' => 
  array (
    0 => 
    array (
      'taxonomy' => 'happyfiles_category',
      'field' => 'term_id',
      'terms' => 
      array (
        0 => 5,
      'include_children' => true,
      'removeNoTerms' => false,
      'title' => 'Happy Files Brand Assets',
  'orderby' => 'date',
  'order' => 'DESC',
// The Query
$the_query = new WP_Query( $args );

As you can see I’m using Happy Files for grouping my media files (shouldn’t have any impact on the problem itself, but just to mention it).

The Result looks like the following (as you can see I was able to output the correct “post title”):

Now, there is no way to use the image connected with that attachment “post” as it is not a featured image.

One possibility would be to include the “function return” inside the dynamic image picker, so that i could pass the post_id and use wp_get_attachment_url(get_the_ID()); for example.

A workaround (meanwhile, for anyone facing a similar problem) is to use a code-block and put the following inside of it:

$src = wp_get_attachment_url(get_the_ID());
echo "<img src='{$src}' class='brand-image' />";

You’re then able to style the image via a Relative-Style Selector inside of cwicly.

As always, hope it’s understandable what I mean - if not, please feel free to ask! :wink:

PS: It would be also cool to have some more dynamic options like alt-text and so on (for the wishlist :slight_smile: )


Hi there @Wolfgang,

Thanks for the report.

Indeed, there is no easy way to dynamically display the attachment using the image block, so we’ll get that fixed in the next updates, thanks for bringing this up.

As a side note, the Image Alt property does support dynamic values in the following format: {title}


Hey @Louis ,

just wanted to follow-up as I’m correcting the site I’ve mentioned above and I thought, that you have implemented not only the option inside the link-selector but also inside the image dynamic SRC-Selector.

Just to avoid any misscommunication. Inside the image block the get_attachment_url() option is not available yet and will be available in a future update, right?

(Referring to this one here: Post URL Dynamic Link wrong value when querying attachment - #4 by Louis)

Thanks in Advance for your Answer! :wink:


Hello @Wolfgang,

Attachment URL source has been added to the Image block WordPress data selector in

I’d be grateful if you could let me know if this works correctly on your end.

Thanks in advance.