Answers.Body: <p>I've managed to achieve something which works in the least technical way I can think of. Other solutions might involve migrating data directly within the database, but I figure this is a good starting point. </p>
  
  <p>Let me know how you get on.</p>
  
  <ol>
  <li>Create an RSS feed, <strong>ensuring that the data you want to move</strong> is populating the feed.</li>
  </ol>
  
  <p>Here's a <a href="https://craftcms.com/docs/templating/rss-feed" rel="noreferrer">RSS template from the CraftCMS documentation</a>...</p>
  
  <ol start="2">
  <li>Grab the <a href="https://github.com/engram-design/FeedMe" rel="noreferrer">FeedMe plugin</a>...</li>
  </ol>
  
  <p>Within FeedMe, the Entry Title is required for it to work, so, <strong>if the Entry Title is what you need to move</strong> to another field, you will need to make sure  it appears more than once within a RSS-item e.g.</p>
  
  <pre><code>        {% for entry in craft.entries.section('location').find() %}
          &lt;item&gt;
              &lt;title&gt;{{ entry.title }}&lt;/title&gt;
              &lt;link&gt;{{ entry.title }}&lt;/link&gt;
              ...
          &lt;/item&gt;
          {% endfor %}
  </code></pre>
  
  <p>In my test example, I have a Channel called '<strong>Locations</strong>' - the Title field contains names of Cities.</p>
  
  <p>I want to migrate these Titles, to a new custom field called '<strong>City name</strong>'.</p>
  
  <ol start="3">
  <li><p>Within FeedMe, create a new Feed, choosing the destination <strong>Section</strong> and <strong>Content Type</strong>. Hit the 'Save &amp; Continue' button.</p></li>
  <li><p>The last screen of FeedMe allows you to 'field match' (assign) the different RSS tag content, to a specific field e.g. 'Link' -> 'City name'. See image below...</p></li>
  </ol>
  
  <p><a href="https://i.sstatic.net/Xrvhx.png" rel="noreferrer"><img src="https://i.sstatic.net/Xrvhx.png" alt="enter image description here"></a></p>
  
  <p>In my test, I migrated field contents between two fields within the SAME <strong>Section</strong> and <strong>Content-Type</strong>.</p>
  
  <p>Thoughts welcome.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-08T22:08:45.870Z
Answers.LastActivityDate: 2016-06-08T22:08:45.870Z
Answers.UserDisplayName: Matt P
Body: <p>Right now, we have a matrix field called post body which has all our content, we have text, image, video etc... In our image block we have 2 fields, An asset field called <code>image</code> &amp; a plain text field called <code>caption</code>.</p>
  
  <p>When I first set this site up, admittedly I didn't plan it properly at all and now we allow several images to be uploaded in the single field but we want to be able to set individual captions for each of the images. </p>
  
  <p>Not sure if this is the right way to phrase the question, how would I go about moving the contents of postbody.block.caption to postbody.block.image.caption for every image in that field? </p>
  
  <p>This is going to be a once off migration of content so I'm not sure if it warrants a plugin, would I be able to do this with a quick &amp; dirty sql/yii query?</p>
  
  <p>Here is what I have so far </p>
  
  <pre><code>&lt;?php
  
  $craft = require '../craft/app/bootstrap.php';
  
  $criteria = $craft-&gt;elements-&gt;getCriteria(Craft\ElementType::MatrixBlock);
  $criteria-&gt;fieldId = $craft-&gt;fields-&gt;getFieldByHandle('postBody')-&gt;id;
  $criteria-&gt;type = "image";
  $criteria-&gt;limit = null;
  $blocks = $criteria-&gt;find();
  
  foreach ($blocks as $block) {
      if ($block-&gt;caption) {
          foreach($block-&gt;image as $image) {
              $block-&gt;image-&gt;imageCaption = $block-&gt;caption;
          }
          $block-&gt;caption = NULL;
          $craft-&gt;matrix-&gt;saveBlock($block);
      }
  }
  ?&gt;
  </code></pre>
  
  <p>But that gives <code>Property "Craft\MatrixBlockModel.caption" is not defined.</code></p>
  
  <p><em>Edit</em>  I’m now at the stage where the contents of the caption field has been saved to each of the images in that block, but i cant seem to set the <code>caption</code> field on the block to null. Here is what I have at this stage</p>
  
  <pre><code> $craft = require '../craft/app/bootstrap.php';
  
  $criteria = $craft-&gt;elements-&gt;getCriteria(Craft\ElementType::MatrixBlock);
  $criteria-&gt;fieldId = $craft-&gt;fields-&gt;getFieldByHandle('postBody')-&gt;id;
  $criteria-&gt;type = "image";
  $criteria-&gt;limit = null;
  $blocks = $criteria-&gt;find();
  
  foreach ($blocks as $block) {
      if ($block-&gt;caption) {
  
          $caption = "&lt;p&gt;".$block-&gt;getContent()-&gt;caption."&lt;/p&gt;";
          foreach($block-&gt;image as $image) {
              $asset = $craft-&gt;elements-&gt;getElementById($image-&gt;id);
              if(empty($asset-&gt;getContent()-&gt;imageCaption)) {
                  $asset-&gt;getContent()-&gt;imageCaption = $caption;
                  $success = $craft-&gt;assets-&gt;storeFile($asset);
              }
          }
  
          $block-&gt;setContent(array(
              'caption' =&gt; '',
          ));
  
          $success = $craft-&gt;matrix-&gt;saveBlock($block);
  
          dd($success);
  
      }
  }
  </code></pre>
  
Tags: <field><content>
Title: Migrate contents between fields?
ThreadText: # Migrate contents between fields?
  
  (Asked by: username_0 on 2015-12-16)
  
  Right now, we have a matrix field called post body which has all our content, we have text, image, video etc... In our image block we have 2 fields, An asset field called `image` & a plain text field called `caption`.
  
  When I first set this site up, admittedly I didn't plan it properly at all and now we allow several images to be uploaded in the single field but we want to be able to set individual captions for each of the images.
  
  Not sure if this is the right way to phrase the question, how would I go about moving the contents of postbody.block.caption to postbody.block.image.caption for every image in that field?
  
  This is going to be a once off migration of content so I'm not sure if it warrants a plugin, would I be able to do this with a quick & dirty sql/yii query?
  
  Here is what I have so far
  
  ```
  <?php
  
  $craft = require '../craft/app/bootstrap.php';
  
  $criteria = $craft->elements->getCriteria(Craft\ElementType::MatrixBlock);
  $criteria->fieldId = $craft->fields->getFieldByHandle('postBody')->id;
  $criteria->type = "image";
  $criteria->limit = null;
  $blocks = $criteria->find();
  
  foreach ($blocks as $block) {
      if ($block->caption) {
          foreach($block->image as $image) {
              $block->image->imageCaption = $block->caption;
          }
          $block->caption = NULL;
          $craft->matrix->saveBlock($block);
      }
  }
  ?>
  
  ```
  
  But that gives `Property "Craft\MatrixBlockModel.caption" is not defined.`
  
  *Edit* I’m now at the stage where the contents of the caption field has been saved to each of the images in that block, but i cant seem to set the `caption` field on the block to null. Here is what I have at this stage
  
  ```
   $craft = require '../craft/app/bootstrap.php';
  
  $criteria = $craft->elements->getCriteria(Craft\ElementType::MatrixBlock);
  $criteria->fieldId = $craft->fields->getFieldByHandle('postBody')->id;
  $criteria->type = "image";
  $criteria->limit = null;
  $blocks = $criteria->find();
  
  foreach ($blocks as $block) {
      if ($block->caption) {
  
          $caption = "<p>".$block->getContent()->caption."</p>";
          foreach($block->image as $image) {
              $asset = $craft->elements->getElementById($image->id);
              if(empty($asset->getContent()->imageCaption)) {
                  $asset->getContent()->imageCaption = $caption;
                  $success = $craft->assets->storeFile($asset);
              }
          }
  
          $block->setContent(array(
              'caption' => '',
          ));
  
          $success = $craft->matrix->saveBlock($block);
  
          dd($success);
  
      }
  }
  
  ```
  
  **Tags:** field, content
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-06-08. Score: 5
  
  I've managed to achieve something which works in the least technical way I can think of. Other solutions might involve migrating data directly within the database, but I figure this is a good starting point.
  
  Let me know how you get on.
  
  1. Create an RSS feed, **ensuring that the data you want to move** is populating the feed.
  
  Here's a [RSS template from the CraftCMS documentation](https://craftcms.com/docs/templating/rss-feed)...
  
  2. Grab the [FeedMe plugin](https://github.com/engram-design/FeedMe)...
  
  Within FeedMe, the Entry Title is required for it to work, so, **if the Entry Title is what you need to move** to another field, you will need to make sure it appears more than once within a RSS-item e.g.
  
  ```
          {% for entry in craft.entries.section('location').find() %}
          <item>
              <title>{{ entry.title }}</title>
              <link>{{ entry.title }}</link>
              ...
          </item>
          {% endfor %}
  
  ```
  
  In my test example, I have a Channel called '**Locations**' - the Title field contains names of Cities.
  
  I want to migrate these Titles, to a new custom field called '**City name**'.
  
  3. Within FeedMe, create a new Feed, choosing the destination **Section** and **Content Type**. Hit the 'Save & Continue' button.
  4. The last screen of FeedMe allows you to 'field match' (assign) the different RSS tag content, to a specific field e.g. 'Link' -> 'City name'. See image below...
  
  [![enter image description here](https://i.sstatic.net/Xrvhx.png)](https://i.sstatic.net/Xrvhx.png)
  
  In my test, I migrated field contents between two fields within the SAME **Section** and **Content-Type**.
  
  Thoughts welcome.
  
  
  ---
  
  