Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I try to attach lastmod field to taxonomy term using following rule:
Get max timestamp from list of all nodes referenced to current term.
/**
* Implements hook_xmlsitemap_link_alter().
*/
function [my_super_module]_xmlsitemap_link_alter(&$link) {
if ($link['type'] == 'taxonomy_term') {
// search for nodes referenced to current taxonomy term
$nids = db_select('taxonomy_index', 'ti')
->fields('ti', array('nid'))
->condition('ti.tid', $link['id'])
->execute()
->fetchAll(PDO::FETCH_COLUMN, 0);
$timestamps = array();
foreach($nids as $nid) {
$node = node_load($nid); // Here i have to load node. Why?
// Always recalculate changefreq and changecount.
$timestamps = array_merge($timestamps, xmlsitemap_node_get_timestamps($node));
}
$link['lastmod'] = count($timestamps) ? max($timestamps) : 0;
}
}
It's okey but xmlsitemap_node_get_timestamps() doesn't requires full-loaded node at all. It's enough just node->nid as argument.
Comments
Comment #1
holdmann CreditAttribution: holdmann commentedHere the patch
Comment #2
holdmann CreditAttribution: holdmann commentedComment #4
holdmann CreditAttribution: holdmann commented#1: 1856572-2-xmlsitemap_node_xmlsitemap_node_get_timestamps_fixes.patch queued for re-testing.
Comment #6
holdmann CreditAttribution: holdmann commentedComment #8
holdmann CreditAttribution: holdmann commentedThird try
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedI think this is a won't fix. Dave Reid, can you please chime in on this?