posts; $now = current_time('mysql'); $name_or_id = ''; $orderby = 'post_date'; if( !$id || 'GETPOST' == $id || 'GETRANDOM' == $id ) { if( $wp_version < 2.1 ) $query_suffix = "post_status = 'publish'"; else $query_suffix = "post_type = 'post' AND post_status = 'publish'"; } elseif('GETPAGE' == $id) { if($wp_version < 2.1) $query_suffix = "post_status = 'static'"; else $query_suffix = "post_type = 'page' AND post_status = 'publish'"; } elseif('GETSTICKY' == $id) { if($wp_version < 1.5) $table .= ', ' . $tablepostmeta; else $table .= ', ' . $wpdb->postmeta; $query_suffix = "ID = post_id AND meta_key = 'sticky' AND meta_value = 1"; } else { $query_suffix = "(post_status = 'publish' OR post_status = 'static')"; if(is_numeric($id)) { $name_or_id = "ID = '$id' AND"; } else { $name_or_id = "post_name = '$id' AND"; } } if('GETRANDOM' == $id) $orderby = 'RAND()'; $post = $wpdb->get_row("SELECT * FROM $table WHERE $name_or_id post_date <= '$now' AND $query_suffix ORDER BY $orderby DESC LIMIT 1"); get_post_custom($post->ID); if($wp_version < 1.5) start_wp(); else setup_postdata($post); } ?>