Function to get last posts?
Quote from user1 on September 4, 2023, 11:58 amHey, is there a php function to get last postings? Someting like get_forum_posts($count)… we would like to integrate a custom designed sidebar where we tease posts from different areas, also from forum.
Hey, is there a php function to get last postings? Someting like get_forum_posts($count)… we would like to integrate a custom designed sidebar where we tease posts from different areas, also from forum.
Quote from user1 on September 4, 2023, 7:47 pmI solved it like this, perhaps it helps others:
function get_latest_forum_entries($limit=3) { global $asgarosforum; $elements = $asgarosforum->db->get_results("SELECT p.id, p.text, p.date, p.parent_id, p.author_id, t.name, (SELECT COUNT(*) FROM wp_forum_posts WHERE parent_id = p.parent_id) AS post_counter FROM wp_forum_posts AS p LEFT JOIN wp_forum_topics AS t ON (t.id = p.parent_id) WHERE p.forum_id IN(1,2,3,4,5) AND p.id IN (SELECT MIN(p_inner.id) FROM wp_forum_posts AS p_inner GROUP BY p_inner.parent_id) AND t.approved = 1 ORDER BY t.id DESC LIMIT $limit;"); return $elements; }You will have a @return array with entries, having these fields:
- id
- text
- date
- parent_id
- author_id
- name
- post_counter
The list 1,2,3,4,5 in query is my list of forums.
I solved it like this, perhaps it helps others:
function get_latest_forum_entries($limit=3) { global $asgarosforum; $elements = $asgarosforum->db->get_results("SELECT p.id, p.text, p.date, p.parent_id, p.author_id, t.name, (SELECT COUNT(*) FROM wp_forum_posts WHERE parent_id = p.parent_id) AS post_counter FROM wp_forum_posts AS p LEFT JOIN wp_forum_topics AS t ON (t.id = p.parent_id) WHERE p.forum_id IN(1,2,3,4,5) AND p.id IN (SELECT MIN(p_inner.id) FROM wp_forum_posts AS p_inner GROUP BY p_inner.parent_id) AND t.approved = 1 ORDER BY t.id DESC LIMIT $limit;"); return $elements; }
You will have a @return array with entries, having these fields:
- id
- text
- date
- parent_id
- author_id
- name
- post_counter
The list 1,2,3,4,5 in query is my list of forums.
Quote from Jim on September 5, 2023, 12:30 am@user1 FYI, Asgaros Forum provides a widget that does that. Not sure if it meets your needs. Attached is a screenshot of it in a sidebar
@user1 FYI, Asgaros Forum provides a widget that does that. Not sure if it meets your needs. Attached is a screenshot of it in a sidebar
Uploaded files: