Drip Feeding Products into Wordpress Posts Automatically
Question
I want to be able to add posts automatically containing the product name as the title, product description and image etc as the content of the wordpress post. So say 10 products a day will be published as posts automatically. What would be the best way round to do something like this?
Thanks
Hi David,
Thank You for your reply. Yes I can import posts into wordpress from an RSS feed.
Yes please do help me modify the RSS export script.
Cheers
Hi,
I have thought about this and I think the best thing to do is have a table in the database to record the progress of the RSS feed through the products table, so each time you request rss.php it checks a new `drip` table to get the start value to use, and then increments the value by the number of items you want each time you run rss.php (defaults to 10 in the code below).
To do this, firstly, upload the following as dbmod.php and then browse to it:
dbmod.php
<?php
require("includes/common.php");
$sql = "DROP TABLE `".$config_databaseTablePrefix."drip`";
database_queryModify($sql,$result);
$sql = "CREATE TABLE `".$config_databaseTablePrefix."drip`
(
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`start` INT ( 11 ) NOT NULL
) ENGINE = MYISAM
";
database_queryModify($sql,$result);
$sql = "INSERT INTO `".$config_databaseTablePrefix."drip` SET start='0'";
database_queryModify($sql,$result);
print "Done.";
?>
You can also browse to dbmod.php again whenever you want to reset the starting point back to 0.
Next here, is a modified version of the rss.php script that has the Buy URL as link instead of the link to the product on your Price Tapestry installation, although this can of course be changed to whatever you need if that's not suitable. You can change the number of products output in the feed each time on line 1 by changing the value of $count...
rss.php
<?php
$count = 10;
require("includes/common.php");
header("Content-Disposition: attachment; filename=products.xml");
header("Content-Type: text/xml");
print "<?xml version='1.0' encoding='UTF-8'?>";
print "<rss>";
print "<channel>";
$sql = "SELECT * FROM `".$config_databaseTablePrefix."drip`";
database_querySelect($sql,$rows);
$start = $rows[0]["start"];
$sql = "UPDATE `".$config_databaseTablePrefix."drip` SET start = start + ".$count;
database_queryModify($sql,$result);
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` LIMIT ".$start.",".$count;
if (database_querySelect($sql,$rows))
{
foreach($rows as $row)
{
print "<item>";
if ($config_useRewrite)
{
$link = "http://".$_SERVER["HTTP_HOST"].tapestry_buyURL($row);
}
else
{
$link = $row["buy_url"];
}
print "<title>".$row["name"]."</title>";
print "<link>".$link."</link>";
print "<description>".$row["description"]."</description>";
print "</item>";
}
}
print "</channel>";
print "</rss>";
?>Hope this helps!
Cheers,
David.
Hi,
Are you able to import posts IN to WordPress from an RSS feed?
If that would be an option, I can help you modify the RSS export script from this thread into a version that can be made to progress through the database without returning the same 10 items again...
Cheers,
David.