Setting post_id for single.php based on URL without a redirect

I figured it out, here is the solution for anyone else wondering how to do something like this: function force_ID($query) { global $wpdb; if (substr($_SERVER[‘REQUEST_URI’],-5) == ‘.html’) { $post_id = $wpdb->get_var($wpdb->prepare(“SELECT ID FROM $wpdb->posts WHERE post_name=%s AND post_status=”publish””,substr(basename($_SERVER[‘REQUEST_URI’]),0,-5))); if ($post_id > 0) $query->set(‘page_id’,$post_id); } } add_action(‘pre_get_posts’,’force_ID’); In examining the wp-includes/query.php file, I noticed that the … Read more

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

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