Issue to get wp_get_attachment_image with cmb2

I have a problem get the image with cmb2, I have tried in many ways without successm according to the documentation, this is fine, what can I be doing wrong? add_action( ‘cmb2_admin_init’, ‘cmb2_sample_metaboxes2’ ); function cmb2_sample_metaboxes2() { // Start with an underscore to hide fields from custom fields list $prefix = ‘_textinfo_’; $cmb = new_cmb2_box( … Read more

Display one random image, but only if landscape

I want to pull one random image and use it as a background image —- but ONLY if it’s a landscape image. I found this post: https://stackoverflow.com/questions/37537577/wordpress-query-by-attachment-meta-image-size which is a pretty good explanation of how to start here. For my purposes, landscape can be as simple as width > height (any aspect ratio greater than … Read more

ACF attachment custom field in rest response

I created an extra select option ACF field for media uploader and I would like to retrieve the associated values in Gutenberg MediaUploader onSelect. Is there a workaround for this case? 1 Answer 1 Check out ACF to REST API – https://github.com/airesvsg/acf-to-rest-api You can optionally turn on/off which fields you want to enable. // Enable … Read more

How can I get full attachment url from wp_get_attachment_metadata?

I want to get all sizes of an attachment. I can use wp_get_attachment_metadata to do this. But it only return filenames, not file urls. How can I do this? This is a workaround, but doesn’t take stuff such as CDNs into account: $attachment_id = get_term_meta( $term->term_id, ‘thumbnail_id’, true); $image = wp_get_attachment_metadata($attachment_id); $image[‘id’] = $attachment_id; foreach($image[‘sizes’] … Read more

How to get images from EDD post?

I use Easy Digital Downloads plugin and I wish to get images from the downloads posts types! But with my code, nothing return! Someone for help? <?php $attachments = get_posts( array( ‘post_type’ => ‘attachment’, ‘orderby’ => ‘menu_order’, ‘numberposts’ => 5, ‘post_status’ => null, ‘post_parent’ => $post->ID, ‘post_mime_type’ => ‘image’ )); if ( $attachments ) { … Read more

Get attachment next and previous by author only

I’m trying to get the next and previous attachment by the user it’s currently displaying, this is what I have and it works great except it gets all of the attachments instead of just the ones from a specific user. <p> <?php $attachment_size = apply_filters( ‘twentyten_attachment_size’, 900 ); echo wp_get_attachment_image($post->ID, array( $attachment_size, 9999) ); // … Read more

How to add multiple checkbox elements to media attachments?

Based on solved question from: How to add a checkbox element to attachments editor with example Theres an example of multiple Checkboxes, for example: Colors, patterns, etc… A grouped list but using checkboxes? Tips to save and remember checked options on edit? Thanks in advance. 1 Answer 1 Like @Bainternet said, it is the same … Read more

Getting attachment images is cloning some of them

So, i got this code to retrieve the images inserted in a gallery within a post: <?php $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’=>’inherit’, ‘post_mime_type’ => ‘image’, ‘post_parent’ => $post->ID, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’ ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $attachment) { $image_attributes = wp_get_attachment_image_src( $attachment->ID, … Read more