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:

[cc lang=”php”]include(“/path/to/whmcs/configuration.php”);
$link = mysql_connect($db_host,$db_username,$db_password);
$query = “SELECT * FROM tblannouncements WHERE published=’on’ ORDER BY date DESC LIMIT 0,3”;
while($data = mysql_fetch_array($result)) {
$id = $data[“id”];
$date = $data[“date”];
$title = $data[“title”];
$announcement = $data[“announcement”];

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.

You May Also Like

Delete all directories more than a week old

This simple linux bash script will delete subdirectories in a directory based…

Command Line Packet Sniff Existing Running Process in Linux

Have you ever come across a server that is doing a lot…

A Simple Java TCP Server and TCP Client

Following up on my previous post, we also had to demonstrate a…