How to run WP_Query to retrieve attachments to posts only from a particular category?

You’ll need to first grab the posts, then grab the attachments that are children of said posts. $my_query = new WP_Query( array( ‘meta_key’ => ‘my_hash’, ‘nopaging’ => true, ‘orderby’ => ‘meta_value’, ‘fields’ => ‘ids’, ‘cat’ => ’60’, )); if ( $post_ids = $my_query->get_posts() ) { $post_ids = implode( ‘,’, $post_ids ); $atts_ids = $wpdb->get_col( “SELECT … Read more

Image Attachment Url Rewrite

Ok so I found the answer. I used the code as per https://wordpress.stackexchange.com/a/56426/37472 and changed all references of ‘series’ to ‘gallery’. That added the required rewritre rule to parse a link like domain.com/landscapes/gallery/123/ to index.php?attachment_id=123. My assumption was that wordpress would display the default permalink that is generated by get_permalink() in the domain.com/landscapes/gallery/123/ format. It … Read more

File upload, uploads only file name

The WordPress codex states that “The file MUST be on the uploads directory”. I’ve added a line to move the uploaded file into the uploads directory and changed the guid path. if( isset( $_POST[‘submit’] ) ) { $filename = $_FILES[‘file’][‘name’]; $wp_filetype = wp_check_filetype( basename($filename), null ); $wp_upload_dir = wp_upload_dir(); // Move the uploaded file into … Read more

How to create a CSV on the fly and send as an attachment using wp_mail?

That’s because wp_mail expects the attachment to be a filename (filepath) that it can attach and send. You are supplying a string containing the contents of the file: function create_csv() { $filepath=”/path/to/the/file.csv”; $fd = fopen($filepath, ‘w’); if($fd === FALSE) { die(‘Failed to open temporary file’); } $records = array( array(‘dummy’, ‘data’, ‘found’, ‘here’) ); fputcsv($fd, … Read more

Attachment page per category

Attachments does not have categories, so a simple in_category() or has_category() check will not work. What we will need to do to solve is this issue is the following Get the current attachment object. We will make use of get_queried_object() which will hold the current post object of the attachment being viewed Determine the post … Read more

Get url from file uploaded in Media Library

If understand your question correctly, I think this can get the job done. Use get_attachment_link instead of wp_get_attachment_url and then echo the title. <?php $attachment_id = 2582; $attachment_page = get_attachment_link( $attachment_id ); ?> <a href=”https://wordpress.stackexchange.com/questions/255020/<?php echo $attachment_page; ?>”><?php echo get_the_title($attachment_id ); ?></a>

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