Troubles with code for upload a image

well i look and i look and finally i found this work that work for me. $upload = wp_upload_bits( $_FILES[‘image’][‘name’], null, file_get_contents( $_FILES[‘image’][‘tmp_name’] ) ); $wp_filetype = wp_check_filetype( basename( $upload[‘file’] ), null ); $wp_upload_dir = wp_upload_dir(); $attachment = array( ‘guid’ => $wp_upload_dir[‘baseurl’] . _wp_relative_upload_path( $upload[‘file’] ), ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename( $upload[‘file’] … Read more

Limit attachment caption characters

do you have a custom meta field associated with the image? if so place this in your functions.php: <?php $trim_length = 21; //desired length of text to display $custom_field = ‘your custom field key here’; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { echo ‘<p>I want to use: ‘ . rtrim(substr($value,0,$trim_length)) . ‘…</p>’; } ?> … Read more

Attachment file display link text

I’ve changed the button to: <a class=”button big brand-1″ a href=”https://wordpress.stackexchange.com/questions/221483/<?php echo wp_get_attachment_url($attachment->ID, false); ?>”> <?php echo $default_strings[‘price_text’][ $lang ]; ?> </a> a href is added around the wp_get_attachment_url rather than using the_attachment_link which contains the whole link.

How to get Attachments(image) with specific width\height ratio

The _wp_attachment_metadata stores serialized data. It’s not meant to be used directly in queries to match results. Instead hook add_attachment action and store original image’s dimensions into separate post meta properties. After you’re happy with how it works follow Rarst’s advice and find a way to walk all existent image attachments and generate those meta … Read more

Using $_FILES variable into the same function for uploading images and files

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 ($images[‘name’][$key]) { $image = array( ‘name’ => $images[‘name’][$key], ‘type’ => … Read more

Attachment Metadata inside of Loop

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’ )); while ( $the_query->have_posts() ) … Read more

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