Pulling Post Image Attachments in WordPress 3.9
Pulling Post Image Attachments in WordPress 3.9
Pulling Post Image Attachments in WordPress 3.9
Add the following condition before the file upload functionality – $allowedExts = array(“pdf”, “jpg”, “png”); $temp = explode(“.”, $_FILES[“attachment”][“name”]); $extension = end($temp); if ((($_FILES[“file”][“type”] == “image/pdf”) || ($_FILES[“file”][“type”] == “image/jpg”) || ($_FILES[“file”][“type”] == “image/png”)) && ($_FILES[“file”][“size”] < 1000000) && in_array($extension, $allowedExts)) { //your file upload code and other stuffs } else { echo “Invalid file”; … Read more
You mentioned using the class in your comment. You could try just adding max-width:100% to the css from the link you provided. Or use jQuery: $(document).ready(function(){ $(‘img.fulljust’).each(function(){ if($(this).width() > 300){ $(this).css({ ‘width’ : ‘100vw’; ‘position’: ‘relative’; ‘left’: ‘50%’; ‘right’: ‘50%’; ‘margin-left’: ‘-50vw’; ‘margin-right’: ‘-50vw’; }); } }); }); EDIT: I realized I didn’t answer your … Read more
I wonder if you’re looking for the core attachment_url_to_postid() function that uses: $sql = $wpdb->prepare( “SELECT post_id FROM $wpdb->postmeta WHERE meta_key = ‘_wp_attached_file’ AND meta_value = %s”, $path ); $post_id = $wpdb->get_var( $sql ); Note the extra meta key _wp_attached_file check compared to your current snippet. If you need to check if an image url … Read more
You can solve your problem with a WordPress Cron Job. I wrote this code and cron scheduler. Also i tested this code on my localhost. If you add this code to your theme’s functions.php you can solve your problem. Cron job and function will work every day and search old posts and their attachments for … Read more
Gallery “order” is saved in the gallery shortcode itself. Take a look at the code for the gallery using the “text” editor, then drag the images around, and look at the raw code again. To make this work, you will have to parse the post content for the gallery shortcode and extract its data. Something … Read more
Show prev and next post links for parent post of current image in attachment page?
After some research, I found that Custom Post Types don’t store post_parent for attachments or may be requires some tweaking with register_post_type(). However, I found that when uploading attachments to regular posts, WordPress sends a post_id with AJAX and same is not happened with Custom Post Types. So, we need to assign post_id to Custom … Read more
You can get the original attachment filename via wp_get_attachment_url: echo basename( wp_get_attachment_url( $post->ID ) ); or in the form of the example you provided: <a href=”https://wordpress.stackexchange.com/questions/91547/mailto:[email protected]?Subject=Image: <?php the_title(); ?> – <?php echo basename( wp_get_attachment_url( $post->ID ) ); ?>”>Get in touch about this image</a>
I think I find the answer– wp-include/post.php: if ( ! in_array( $post_status, array( ‘inherit’, ‘private’ ) ) ) $post_status=”inherit”; So, whatever status will be saved as “inherit”.