Display last post as default
-
In my installation, I use this shortcode but I wanted to set it up so that instead of having to specify the ID of a post, I wanted it to automatically show the last post unless one was specified. I did the following in function __construct():
1) Add $wpdb to the global declaration
2) Add the following line before the declaration of $this->defaults:
$last_post_id = $wpdb->get_var( $wpdb->prepare( “SELECT MAX(ID) FROM {$wpdb->posts} WHERE post_type=’post’ and post_status=’publish’ LIMIT 1”);
3) In $this->defaults, set the default ‘id’ to $last_post_idCan I suggest that this idea be incorporated into the shortcode either as a default or as an option that could be set?
The topic ‘Display last post as default’ is closed to new replies.