Title: Convert code to WP 2.6
Last modified: August 19, 2016

---

# Convert code to WP 2.6

 *  [drhallows](https://wordpress.org/support/users/drhallows/)
 * (@drhallows)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/convert-code-to-36/)
 * Hello all,
 * I want to use the Google News Sitemap Plugin but is not working in 2.6, because
   i need to change a line of code.
 * function get_category_keywords($newsID)
    { global $wpdb; ** $categories = $wpdb-
   >get_results(“SELECT category_id FROM $wpdb->post2cat WHERE post_id=$newsID”);**
   $i = 0; $categoryKeywords = “”; foreach ($categories as $category) { if ($i>0){
   $categoryKeywords.= “, “;} //Comma seperator $categoryKeywords.= get_catname(
   $category->category_id); //ammed string $i++; } return $categoryKeywords; //Return
   post category names as keywords }
 * function write_google_news_sitemap()
    {
 *  global $wpdb;
    // Fetch options from database $permalink_structure = $wpdb->
   get_var(“SELECT option_value FROM $wpdb->options WHERE option_name=’permalink_structure'”);
   $siteurl = $wpdb->get_var(“SELECT option_value FROM $wpdb->options WHERE option_name
   =’siteurl'”);
 *  // Output XML header
 *  // Begin urlset
    $xmlOutput = “<urlset xmlns=\”[http://www.sitemaps.org/schemas/sitemap/0.9](http://www.sitemaps.org/schemas/sitemap/0.9)\”
   xmlns:news=\”[http://www.google.com/schemas/sitemap-news/0.9](http://www.google.com/schemas/sitemap-news/0.9)\”
   >\n”;
 *  // Select all posts
    //$rows = $wpdb->get_results(“SELECT ID, post_date_gmt //
   FROM $wpdb->posts WHERE post_status=’publish'”);
 *  //Limit to last 3 days, 1000 items
    $rows = $wpdb->get_results(“SELECT ID, post_date_gmt
   FROM $wpdb->posts WHERE post_status=’publish’ AND (DATEDIFF(CURDATE(), post_date_gmt)
   <=3) ORDER BY post_date_gmt DESC LIMIT 0, 1000″);
 *  // Output sitemap data
    foreach($rows as $row){ $xmlOutput.= “\t<url>\n”; $xmlOutput.
   = “\t\t<loc>”; $xmlOutput.= get_permalink($row->ID); $xmlOutput.= “</loc>\n”;
   $xmlOutput.= “\t\t<news:news>\n”; $xmlOutput.= “\t\t<news:publication_date>”;
   $thedate = substr($row->post_date_gmt, 0, 10); $thetime = substr($row->post_date_gmt,
   11, 20); $xmlOutput.= $thedate . ‘T’ . $thetime . ‘Z’; $xmlOutput.= “</news:publication_date
   >\n”; $xmlOutput.= “\t\t<news:keywords>”;
 *  //Use the categories for keywords
    $xmlOutput.= get_category_keywords($row->
   ID);
 *  $xmlOutput.= “</news:keywords>\n”;
    $xmlOutput.= “\t\t</news:news>\n”; $xmlOutput.
   = “\t</url>\n”; }
 *  // End urlset
    $xmlOutput.= “</urlset>\n”; $xmlOutput.= “<!– Last build time:“.
   date(“F j, Y, g:i a”).”–>”;
 *  $xmlFile = “../google-news-sitemap.xml”;
    $fp = fopen($xmlFile, “w+”); // open
   the cache file “news-sitemap.xml” for writing fwrite($fp, $xmlOutput); // save
   the contents of output buffer to the file fclose($fp); // close the file }
 * add_action(‘publish_post’, ‘write_google_news_sitemap’);
    add_action(‘save_post’,‘
   write_google_news_sitemap’); add_action(‘delete_post’, ‘write_google_news_sitemap’);?
   >
 * Any idea? Thanks!

Viewing 1 replies (of 1 total)

 *  [chrisjinks](https://wordpress.org/support/users/chrisjinks/)
 * (@chrisjinks)
 * [17 years, 9 months ago](https://wordpress.org/support/topic/convert-code-to-36/#post-834155)
 * Hi DrHallows,
 * I wrote the original script for this plugin and have recently updated it for 
   all you people using the newer WordPress 2.3+ database taxonomy.
 * Please try the latest version (v1.1) from here: [http://wordpress.org/extend/plugins/google-news-sitemap-generator/](http://wordpress.org/extend/plugins/google-news-sitemap-generator/)
 * I have plenty of other developments in the pipeline for this plugin, but this
   should suffice for now.

Viewing 1 replies (of 1 total)

The topic ‘Convert code to WP 2.6’ is closed to new replies.

## Tags

 * [sitemap](https://wordpress.org/support/topic-tag/sitemap/)

 * 1 reply
 * 2 participants
 * Last reply from: [chrisjinks](https://wordpress.org/support/users/chrisjinks/)
 * Last activity: [17 years, 9 months ago](https://wordpress.org/support/topic/convert-code-to-36/#post-834155)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
