New answers tagged

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


0

in_category relies on a global post - it should only be used within the loop. Instead, use the arguments that are passed to your callback to query the categories assigned to the post being edited and check if one of them is video: $cats = get_the_category( $post['ID'] ); if ( in_array( 'video', wp_list_pluck( $cats, 'slug' ) ) { // In "video" category } ...


0

Is the file correctly saved? Did you try attaching a file via static path? Something like: $attachments = array(WP_CONTENT_DIR ."/uploads/myfile.pdf");


0

Dont mess with all this. Just go to the wordpress dashboard > Media, delete the titles from each picture. Done.


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


0

The answer was found here: http://www.wprecipes.com/how-to-display-category-name-without-link For my purposes, I needed to define the category function and then call it by name-only inside the php echo: <?php $category = get_the_category($attachment->ID); echo 'html goes here'; echo ''.$category[0]->cat_name.'; ?> ...


0

Here's the fix. All the attachment info is now being called inside the php using wp_prepare_attachment_for_js and the info will load for each image in the loop, to display in the photo gallery. It works now. <?php $the_query = new WP_Query(array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'category_name' => 'arch' ...


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


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


0

Everybody has been very useful and I say THANK YOU guys for having helped me out. The problem seems really to be into $_FILES variable which overwrite itself throughout 2 loops. After several tries I've found this solution that works for me and allows to upload both images and files. if ($_FILES) { // I've firstly declared main variables ...


0

I did override something. I did not validation and only build structured to validation and upload function. You can validate file as you needed. if ($_FILES) { // Get the upload attachment files $images = $_FILES['moreimages']; $errors = ''; foreach ($images['name'] as $key => $value) { if ...


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.


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


0

After checking other browsers, I found out that it was a Chrome problem. It looks like it has something to do with Google Chrome notifications. I fixed the problem with adding this CSS to my WordPress admin css file: /* Chrome media library upload button fix */ @media screen and (-webkit-min-device-pixel-ratio:0) { .modal-open .rdr-notifier { ...



Top 50 recent answers are included