我目前正在开设一个新的(WordPress)网站,该网站应该从外部数据库发布空缺职位。出于测试目的,我已经建立了一个与外部数据库连接的WordPress网站。连接没问题,我也可以加载表/行并显示数据(如标题,发布日期,内容等)。但我希望我的外部数据库中的每篇(新)文章都设置为WordPress网站上的新帖子,因此这些文章在网站上有自己的URL /页面。
我已设置数据库并显示如下信息:
/* Set-up database */
$servername = "xxx.xxx.xxx.xxx";
$username = "db_user_external";
$password = "db_password_external";
$database = "db_name_external";
/* Connect to database */
$connectdb = mysql_connect($servername, $username, $password, $database);
/* Query for retrieving data */
$recentposts = 'SELECT * FROM fposts WHERE posts.post_type = "vacancy" AND posts.post_status = "publish" ORDER BY post_date DESC LIMIT 9';
mysql_select_db($database);
$showvacancy = mysql_query( $recentposts, $connectdb );
while($row = mysql_fetch_array($showvacancy, MYSQL_ASSOC)) {
echo
"<p><strong>Vacancy Title:</strong> {$row['post_title']}<br>".
"<strong>Date published:</strong> {$row['post_date']}<br>".
"{$row['post_excerpt']}</p>";
}
/* Closing databaseconnection */
mysql_close($conn);