Please or Register to create posts and topics.

Function to get last posts?

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.

newforum.top has reacted to this post.
newforum.top

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.

Asgaros has reacted to this post.
Asgaros

@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:
  • Screenshot-2023-09-04-at-3.28.59-PM.jpg