Exporting Announcements from WHMCS



Doing some integration work with WHMCS, I found the need to export some of the announcements into WordPress. Since there isn’t any native implementation of this, I found the best way is to export it directly from the database. The PHP code to do this is fairly easy:

1
2
3
4
5
6
7
8
9
10
11
12
include("/path/to/whmcs/configuration.php");
$link = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name);
$query = "SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 0,3";
$result=mysql_query($query);
while($data = mysql_fetch_array($result)) {
  $id = $data["id"];
  $date = $data["date"];
  $title = $data["title"];
  $announcement = $data["announcement"];
  echo("<a href=\"/support/announcements.php?id=$id\">$title</a>");
}

If you wanted to make it more than 3 posts, just change the limit to 5 or 10 or whatever you wish. You can also change the ordering and add additional filters via more SQL statements. If you wanted to do a list, encapulate the code with <ul> and just make them <li> entries.

I’m using this code in a WordPress template but it would work equally as well in any other PHP based application.