Hot answers tagged

2

I mentioned in a comment how it's important to debug your code. Here's why: The images are added first. In the image adding section, you're running this line of code: $_FILES = array("moreimages" => $image); Then when you get to your routine that adds the files, you start with this: $files = $_FILES['morefiles']; Can you see what's wrong here? At ...


2

The code below will only run once whenever a file is uploaded. We keep an array ( $image_mimes ) of acceptable image-mimetypes We get the current attachment mime type We make sure what is given is indeed an image ( because we don't need unnecessary postmeta cluttering our table ) We grab the title from the attachment and set it to the alt-text initially ...


2

I call it when I render a metabox on the edit page. ( Yeah, you shouldn't be using globals in this context - use a foreach loop instead: function get_available_attachments( $post /* This is the post object being edited */ ) { $attachments = []; $attach_query = new WP_Query([ 'post_type' => 'attachment', 'post_status' ...


1

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 ...


1

as per chat discussion, once you get the attachment ID you can get the url using wp_get_attachment_url($attachment_resume_id) so in your case you have to wp_get_attachment_url($record_s->attachment_resume_id)


1

The wp_get_attachment_image_src() function expects you to also pass some kind of attachment ID plus it doesn't grab the image HTML that we need so instead we should use wp_get_attachment_image(). IF a post has a post thumbnail, grab it.ELSE IF the post has any attached images, grab the first one.ELSE maybe show a placeholder? I've defined the else case at ...


1

In WordPress - Attachments are their own post-type which means you just need to update the post using wp_update_post(): $media_post = wp_update_post( array( 'ID' => $attachment_id, 'post_parent' => $post_parent_id, ), true ); if( is_wp_error( $media_post ) ) { error_log( print_r( $media_post, 1 ) ); } In the above you would ...


1

If you are not very familiar and want a plugin that can do all that for you using drag and drop, try WP-TYPES and their CRED plugin. Just don't mind their support, it's really frustrating.



Only top voted, non community-wiki answers of a minimum length are eligible