Shortcode to capture the very last post sumbission from specific space.I need this so bad.
Ross HΒ Ross do you accept the mission. ππ I just need help creating the script.
Just the raw text of the last post in a space?
Yes, that would be perfect! easy so I can simply write the space ID in the shortcode and have it pulled into raw text I can style by styling the shortcode.
Ceez VisionΒ seems very doable. I'll see if I can add it to my shortcodes plugin.
Quick and dirty option:
Use like this: [latestpostbyspaceid id=40]
add_shortcode('latestpostbyspaceid', 'latestpostbyspaceid_shortcode');
function latestpostbyspaceid_shortcode($atts){
global $wpdb;
$space_id = $atts['id'];
$latestpostcontent = $wpdb->get_results("SELECT message_rendered FROM {$wpdb->prefix}fcom_posts WHERE space_id = $space_id ORDER BY ID DESC LIMIT 1");
if ( $wpdb->last_error ) {
echo 'Error: '. $wpdb->last_error;
}
if ($latestpostcontent) {
echo $latestpostcontent[0]->message_rendered;
}
else {
echo 'No post found';
}
}
Thanks Thomas OatesΒ I love that is quick but what do you mean by dirty? lol
Ceez VisionΒ LOL....Dirty = it could probably use more error checking and there may be better ways of doing it. One thing I thought about was having an option to use the space slug instead of the space ID since the slug is easier to get.
Thomas OatesΒ Could we add a topic selection to this?
Ceez VisionΒ Possibly, but it'll be a few days before I can work on it again (too much going on at the moment). Thanks.
Ross HΒ @Thomas_O Could we add a topic selection to this?
Ceez VisionΒ I'll be making updates to this today if there were any other requests or suggestions?
Maybe make it link directly to the post within the community if possible?