Sitecore - publish all items linking to a particular item

Posted 14 Dec 2021 by Marek Musielak

sitecore publish all items linking to a particular item

Sometimes you need to publish all items linking to a particular Sitecore item. While Sitecore has an option to publish item with related items, it only publishes items which are referenced from the item. It does not publish items which link to selected item. Here is easy Sitecore Powershell Extensions script which allows to publish all the items which refer to your selected item:

$myItemId = "{5D95F2CF-6D5C-4AAC-A4C6-21A0A847BCB5}"
$referrers = Get-ItemReferrer -Path $myItemId

foreach ($referrer in $referrers) {
    Publish-Item -Item $referrer
}

This script uses `Get-ItemReferrer` function which utilizes Sitecore Link Database. If you want to be sure that all the items are processed correctly, make sure that your Sitecore Link Database for master database is up to date before running the script.

Sample use case? Imagine you want to delete an item called "Privacy Policy 2021." While deleting, Sitecore displays the Breaking Links dialog and asks you to choose what to do with the existing links to your item. You choose Link to another item and select the "New Privacy Policy 2022" page. Everything seems to be fine, right? Not exactly.

If you publish the deletion of the old "Privacy Policy 2021" item, all the pages that link to that item won't be published automatically because they are no longer referenced by either the old or new item. As a result, in the web database, these pages will still link to the old item.

This is a scenario where you would want to use my script. After choosing the Link to another item option, run my script using the Sitecore ID of the new item. This will publish all the items that now link to the new item, ensuring there are no broken links in the web database.

Comments? Find me on or Sitecore Chat