2009/04/27

How to auto post to Wordpress

  1. Turn on remove_posting at http://yourdomain/wp-admin/options-writing.php
  2. Using below PHP code:
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1)){
   $categories = implode(",", $categories);
   $XML = "<title>$title</title>".
   "<category>$categories</category>".
   "<body>$body</body>";
   $params = array('','',$username,$password,$XML,1);
   $request = xmlrpc_encode_request('blogger.newPost',$params);
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
   curl_setopt($ch, CURLOPT_URL, $rpcurl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_TIMEOUT, 1);
   curl_exec($ch);
   curl_close($ch);
}

2009/04/14

mySQL date function

The SQL to get total order number and total order amount from orders table:

SELECT count(*), sum(order_total) 
FROM orders 
WHERE DAYOFMONTH(last_accessed) = DAYOFMONTH(now()) 
      AND MONTH(last_accessed) = MONTH(now()) 
      AND YEAR(last_accessed) = YEAR(now()) 
      AND record_state = 1

Note:

  1. DAYOFMONTH is synonym of DAY used to get day (ex: 1-31) from a data and time string (ex: 2009-04-14 11:44:02)
  2. Complete mysql date function can be found at here