Skip to main content

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.

Ross FCA

Just the raw text of the last post in a space?

Ceez Vision

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.

Ross FCA

Ceez VisionΒ seems very doable. I'll see if I can add it to my shortcodes plugin.

Thomas Oates

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';
        }
    }

Ceez Vision

Thanks Thomas OatesΒ I love that is quick but what do you mean by dirty? lol

Thomas Oates

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.

Ceez Vision

Thomas OatesΒ Could we add a topic selection to this?

Thomas Oates

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.

Ceez Vision

Ross HΒ  @Thomas_O Could we add a topic selection to this?

Ross FCA

Ceez VisionΒ I'll be making updates to this today if there were any other requests or suggestions?

Ceez Vision

Maybe make it link directly to the post within the community if possible?