How to get post id of last approved comment?

<?php $recent_comments = get_comments( array( ‘number’ => 1, ‘status’ => ‘approve’ ) ); foreach($recent_comments as $comment) : $latest_postid_with_comment = $comment->comment_post_ID; endforeach; ?> Probably way to compress this code into something smaller. But this will work.

Display posts from an array of ID’s

if you set the fields parameter to ids you will get an array of ids instead of unneeded post data ex: $ongoing_args = array( ‘post_type’ => ‘promotions’, ‘meta_key’ => ‘sp_ongoingPromotion’, ‘meta_value’ => 1, ‘fields’ => ‘ids’ ); $current_args = array( ‘post_type’ => ‘promotions’, ‘meta_key’ => ‘sp_endDate’, ‘meta_value’ => date(“Y/m/d”), ‘meta_compare’ => ‘>=’, ‘orderby’ => ‘meta_value’, … Read more

How can I query the db to access current post information?

The correct way: $my_query = new WP_Query(‘posts_per_page=2′); while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php global $post; print_r($post); // <– this is your postStuff ?> <?php endwhile;?> <?php wp_reset_query(); ?> Normally, you dont’t need to globalize the post. There are helper functions that should be used instead to fetch information from the current post

Is there a way to show attachment IDs on the attachment info screen?

You could hook into ‘attachment_fields_to_edit’ and just add a row: <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Show Attachment ID * Version: 2012.06.04 * Author: Thomas Scholz <[email protected]> * Author URI: http://toscho.de * License: MIT * License URI: http://www.opensource.org/licenses/mit-license.php */ if ( ! function_exists( ‘t5_show_attachment_id’ ) ) { add_filter( ‘attachment_fields_to_edit’, ‘t5_show_attachment_id’, … Read more

get_posts by id not working

I have just found an alternative solution: global $post; $current_post = $post->ID; $array=range(1,$current_post); $args = array( “numberposts’ => 5, ‘offset’ => 0, ‘category’ => $category->term_id, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ‘exclude’ => $current_post, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ => true, ‘post__in’ => $array ); $posts = get_posts($args); I’m not sure why the … Read more