How to add a caption to an image attachment in a file list?

You simply need to pass $attachment_id instead of get_post_thumbnail_id() in echo get_post(get_post_thumbnail_id())->post_excerpt; with wptexturize to prevent your markup from breaking other things. Update: As @birgire suggested I think it is better to use get_post_field() instead of directly accessing post property. Updated code:- function soth_output_gallery_file_list( $file_list_meta_key, $img_size ) { // Get the list of files $files … Read more

Get image attachment to a post outside the loop?

try using get_attached_media function and your current $postID $images = get_attached_media( ‘image’, $postID ); this will return a WP_Post object. If you want to get the url, it’s located in the guid key of the object. Use a foreach loop to retrieve them all. foreach( $images as $image ){ $src[] = $image->guid; } To use … Read more

How to get $attachment->ID in custom functions

To get the attachment ID, you need to get the post attachments using get_posts() with the post_type being ‘attachment’ and the post_parent being the ID of the post you’re interested in getting the attachments from. namespace StackExchange\WordPress; function the_post( \WP_Post $post, \WP_Query $query ) { //* Get post attachments $attachments = \get_posts( [ ‘post_type’ => … Read more

Attach a external file as attachement using wp_mail

You can’t attach from a URL. So https://ucarecdn.com/8aa17c61-bd55-4311-8b45-7d9a2efde6c5/ won’t work. You need an absolute path to the file, such as /path/to/my/file.ext. But there are some other problems with your code snippet as well. You use $email_attachement (with a ..chement…) in one place, but then $email_attachment in your wp_mail() call. Also, your “attachment” isn’t a file. … Read more

Gutenberg Block: Image resolution

I was asking the same question in the comments of another question. The solution is (thanks to Кирилл-Меркушев), to get another URL from the onSelect Callback. Before I had this: function onSelectImage( media ) { props.setAttributes( { mediaURL: media.url } ); props.setAttributes( { mediaID: media.id } ); } Then I console logged the media parameter, … Read more

hide attached images of a post

My first recommendation would be to use Advanced Custom Fields to setup a gallery rather than using this method. However, I think you may be able to load your images using Add Media -> Create Gallery which will add a shortcode to your post content You could then use the_content filter and strip_shortcodes to remove … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)