Function returning queried meta value based on current post ID

You can still do the AS with $wpdb, I find it still makes stuff look cleaner. You can use the $wpdb->prepare() method for sanitation. Are you looking for something like this? function combined_downloads($post_id) { global $wpdb; return $wpdb->get_var($wpdb->prepare( “SELECT SUM( meta_value ) FROM $wpdb->postmeta AS m LEFT JOIN $wpdb->posts AS p ON m.post_id = p.ID … Read more

Display list of most recent grandchild (third tier) pages

The only (easy) way this can be done is to query all special, calculate their depth, and then build a new stack of 3-level deep: $grandkids = array(); $specials = get_posts( array( ‘posts_per_page’ => -1, ‘order’ => ‘DESC’, ) ); foreach ( $specials as $special ) { if ( count( get_post_ancestors( $special ) ) === … Read more

Display Upload Author & Get Uploaded Post ID

Attachments count as a built-in post type which is extremely similar to Posts and Pages. The field you’re looking for is post_author. If you have an attachment object: $attachment->post_author If you only have the attachment ID you can use get_post_field( $attachment_id, ‘post_author ); To get the actual Post the the attachment was originally uploaded to … Read more

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