Get MAX post ID from from wp_posts table


<?php
/* Get Max value from wp_posts */
global $wpdb;
$table_name = $wpdb->prefix . “posts”;
$post_ids = $wpdb->get_results(“SELECT MAX(ID) as max_id FROM $table_name”);

/* stdclass object to array in PHP */
foreach ($post_ids as $value)
$array[] = $value->max_id;
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s