Answers.Body: <p>If you manipulate your query somewhere else in the code those properties will not reset after you execute it. You'll either reset the properties (for example <code>query.typeId(null).all()</code> or you need the <code>clone</code> <a href="https://docs.craftcms.com/v3/changes-in-craft-3.html#cloning-element-queries" rel="nofollow noreferrer">function</a> </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-11T06:38:01.537Z
Answers.LastActivityDate: 2018-06-11T06:38:01.537Z
Answers.UserDisplayName: Robin Schambach
Body: <p>Just upgraded a website for the first time to Craft 3.
  I had a matrix field called bodyContent which is basically my page builder.
  Issue is not when creating new pages it the only blocks it seems to pick up are the Redactor Field Blocks - </p>
  
  <p>Plain text, fields not nothing else display on the front end.</p>
  
  <p>On my template pages if I try to find the number of blocks - </p>
  
  <pre><code>{{ entry.bodyContent|length }
  </code></pre>
  
  <p>It displays say only 2 if there are 2 rich text fields - it seems to ignore the rest.</p>
  
  <p>Other blocks are generic headers, plain text fields, assets fields for images/documents etc.</p>
  
  <p>But when I view the entry int he CMS all the blocks are still there - though they don't display in Live Preview either.</p>
  
  <p>Really not sure even where to start with this one.  Tried resaving the Matrix Field etc but no success.</p>
  
  <p>Edit - 
  After some more searching thinking it may be related to this:
  <a href="https://craftcms.stackexchange.com/questions/25613/missing-matrix-row-types-on-output-after-upgrade-to-craft-3-subsetting-and-clon">Missing Matrix row types on output after upgrade to Craft 3 (subsetting and cloning ElementQueries)</a></p>
  
  <p>Existing Code block for outputting the matrix field:</p>
  
  <pre><code>    {% if matrixfield is not defined %}
          {% set matrixfield=entry.bodyContent %}
      {% endif %}
      {{ matrixfield|length }}
      {% for block in matrixfield.all() %}
          {{ block.type }}
          {% include "includes/matrix-blocks/" ~ block.type %}   
      {% endfor %}
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Folliwing coments below that can use Elementquery.getRawSql() i tried the following:
  Ok - on outputting: <code>{{ entry.bodyContent.getRawSql() }}</code></p>
  
  <p>I get </p>
  
  <pre><code>`SELECT `elements`.`id`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`slug`, `elements_sites`.`uri`, `elements_sites`.`enabled` AS `enabledForSite`, `matrixblocks`.`fieldId`, `matrixblocks`.`ownerId`, `matrixblocks`.`ownerSiteId`, `matrixblocks`.`typeId`, `matrixblocks`.`sortOrder`, `content`.`id` AS `contentId`, `content`.`field_heading_size`, `content`.`field_heading_heading`, `content`.`field_text_text`, `content`.`field_image_caption`, `content`.`field_image_position`, `content`.`field_video_videoUrl`, `content`.`field_gallery_layout`, `content`.`field_gallery_galleryType`, `content`.`field_textImageSection_sectionHeading`, `content`.`field_textImageSection_imageColumnPosition`, `content`.`field_textImageSection_imageFullHeight`, `content`.`field_textImageSection_text`, `content`.`field_textImageSection_imageColumnWidth`, `content`.`field_textImageSection_lightboxOnImage`, `content`.`field_staticBlock_staticBlock`, `content`.`field_plainTextHtml_plainTextHtml` FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `elementsSitesId`, `content`.`id` AS `contentId` FROM `craft_elements` `elements` INNER JOIN `craft_matrixblocks` `matrixblocks` ON `matrixblocks`.`id` = `elements`.`id` INNER JOIN `craft_elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id` INNER JOIN `craft_matrixcontent_bodycontent` `content` ON `content`.`elementId` = `elements`.`id` WHERE (`matrixblocks`.`fieldId`='16') AND (`matrixblocks`.`ownerId`='109') AND (`matrixblocks`.`typeId`='3') AND (`elements_sites`.`siteId`=1) AND (`content`.`siteId`=1) AND (`elements`.`archived`=FALSE) ORDER BY `matrixblocks`.`sortOrder`) `subquery` INNER JOIN `craft_matrixblocks` `matrixblocks` ON `matrixblocks`.`id` = `subquery`.`elementsId` INNER JOIN `craft_elements` `elements` ON `elements`.`id` = `subquery`.`elementsId` INNER JOIN `craft_elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`elementsSitesId` INNER JOIN `craft_matrixcontent_bodycontent` `content` ON `content`.`id` = `subquery`.`contentId` ORDER BY `matrixblocks`.`sortOrder`
  </code></pre>
  
  <p>Near the end of that I notice a bit</p>
  
  <pre><code>AND (`matrixblocks`.`typeId`='3')
  </code></pre>
  
  <p>Is that only pulling in the block of 1 type?</p>
  
  <p><strong>Update</strong>
  In my header I had been pulling in a meta description with the code:</p>
  
  <pre><code>{% if entry.bodyContent|length %}
     {% set customdescription = entry.bodyContent.type('text').one()|striptags|slice(0, 155) %}
  {% endif %}
  </code></pre>
  
  <p>Which was manipulating for the code below. I resolved by using the clone option in my header like below:</p>
  
  <pre><code>{% set bodycontent = entry.bodyContent %}
  {% if bodycontent|length %}
     {% set customdescription = clone(bodycontent).type('text').one()|striptags|slice(0, 155) %}
  {% endif %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-09T23:48:27.537Z
Comments.Text: Do you receive the correct blocks when you append a `status(null).enabledForSite(false)` to the query?
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-10T20:42:11.060Z
Comments.Text: Thanks - but that made no difference - just my text blocks displayed again.
Comments.UserDisplayName: mmc501
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-11T05:15:01.393Z
Comments.Text: Then there must be something wrong at some other point in your code. Maybe you manipulate those variables before? If it's visible in the CP it must be accessible
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-11T05:17:02.147Z
Comments.Text: It was working fine in Craft 2 - I've tried just outputting directly on the page as opposed to the above code which is in an include - but still getting the same. {{ entry.bodyContent|length}} is still only dislaying 2.
Comments.UserDisplayName: mmc501
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-11T05:18:48.963Z
Comments.Text: You can get the raw sql and check if there are certain conditions attached that doesn't match via `ElementQuery.getRawSql()`
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-11T05:34:24.823Z
Comments.Text: see update in question - see a bit in query `AND ('matrixblocks'.'typeId'='3')`
Comments.UserDisplayName: mmc501
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-11T05:38:31.283Z
Comments.Text: As I said you manipulate your query at some point. You either need to use the copy function or reset the property
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-11T05:46:05.720Z
Comments.Text: Ok - in my header at the top to get a metadescription I have `{% set customdescription = entry.bodyContent.type('text').one()|striptags|slice(0, 155) %}` if I comment that out all blocks are displayed - thanks
Comments.UserDisplayName: mmc501
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-11T05:55:52.093Z
Comments.Text: Do you want to add that as an answer?
Comments.UserDisplayName: mmc501
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-03-27T16:04:23.767Z
Comments.Text: Just want to say this comment / thread has saved me such a headache - i couldn't work out why my matrix blocks were not being output correctly, and going round in circles! sure enough i was doing some manipulation to the query elsewhere.
Comments.UserDisplayName: alexr
Tags: <matrix><craft3>
Title: Matrix field not displaying all blocks on Craft 3 Upgrade
ThreadText: # Matrix field not displaying all blocks on Craft 3 Upgrade
  
  (Asked by: username_0 on 2018-06-09)
  
  Just upgraded a website for the first time to Craft 3.
  I had a matrix field called bodyContent which is basically my page builder.
  Issue is not when creating new pages it the only blocks it seems to pick up are the Redactor Field Blocks -
  
  Plain text, fields not nothing else display on the front end.
  
  On my template pages if I try to find the number of blocks -
  
  ```
  {{ entry.bodyContent|length }
  
  ```
  
  It displays say only 2 if there are 2 rich text fields - it seems to ignore the rest.
  
  Other blocks are generic headers, plain text fields, assets fields for images/documents etc.
  
  But when I view the entry int he CMS all the blocks are still there - though they don't display in Live Preview either.
  
  Really not sure even where to start with this one. Tried resaving the Matrix Field etc but no success.
  
  Edit -
  After some more searching thinking it may be related to this:
  [Missing Matrix row types on output after upgrade to Craft 3 (subsetting and cloning ElementQueries)](https://craftcms.stackexchange.com/questions/25613/missing-matrix-row-types-on-output-after-upgrade-to-craft-3-subsetting-and-clon)
  
  Existing Code block for outputting the matrix field:
  
  ```
      {% if matrixfield is not defined %}
          {% set matrixfield=entry.bodyContent %}
      {% endif %}
      {{ matrixfield|length }}
      {% for block in matrixfield.all() %}
          {{ block.type }}
          {% include "includes/matrix-blocks/" ~ block.type %}   
      {% endfor %}
  
  ```
  
  **UPDATE**
  
  Folliwing coments below that can use Elementquery.getRawSql() i tried the following:
  Ok - on outputting: `{{ entry.bodyContent.getRawSql() }}`
  
  I get
  
  ```
  `SELECT `elements`.`id`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`slug`, `elements_sites`.`uri`, `elements_sites`.`enabled` AS `enabledForSite`, `matrixblocks`.`fieldId`, `matrixblocks`.`ownerId`, `matrixblocks`.`ownerSiteId`, `matrixblocks`.`typeId`, `matrixblocks`.`sortOrder`, `content`.`id` AS `contentId`, `content`.`field_heading_size`, `content`.`field_heading_heading`, `content`.`field_text_text`, `content`.`field_image_caption`, `content`.`field_image_position`, `content`.`field_video_videoUrl`, `content`.`field_gallery_layout`, `content`.`field_gallery_galleryType`, `content`.`field_textImageSection_sectionHeading`, `content`.`field_textImageSection_imageColumnPosition`, `content`.`field_textImageSection_imageFullHeight`, `content`.`field_textImageSection_text`, `content`.`field_textImageSection_imageColumnWidth`, `content`.`field_textImageSection_lightboxOnImage`, `content`.`field_staticBlock_staticBlock`, `content`.`field_plainTextHtml_plainTextHtml` FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `elementsSitesId`, `content`.`id` AS `contentId` FROM `craft_elements` `elements` INNER JOIN `craft_matrixblocks` `matrixblocks` ON `matrixblocks`.`id` = `elements`.`id` INNER JOIN `craft_elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id` INNER JOIN `craft_matrixcontent_bodycontent` `content` ON `content`.`elementId` = `elements`.`id` WHERE (`matrixblocks`.`fieldId`='16') AND (`matrixblocks`.`ownerId`='109') AND (`matrixblocks`.`typeId`='3') AND (`elements_sites`.`siteId`=1) AND (`content`.`siteId`=1) AND (`elements`.`archived`=FALSE) ORDER BY `matrixblocks`.`sortOrder`) `subquery` INNER JOIN `craft_matrixblocks` `matrixblocks` ON `matrixblocks`.`id` = `subquery`.`elementsId` INNER JOIN `craft_elements` `elements` ON `elements`.`id` = `subquery`.`elementsId` INNER JOIN `craft_elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`elementsSitesId` INNER JOIN `craft_matrixcontent_bodycontent` `content` ON `content`.`id` = `subquery`.`contentId` ORDER BY `matrixblocks`.`sortOrder`
  
  ```
  
  Near the end of that I notice a bit
  
  ```
  AND (`matrixblocks`.`typeId`='3')
  
  ```
  
  Is that only pulling in the block of 1 type?
  
  **Update**
  In my header I had been pulling in a meta description with the code:
  
  ```
  {% if entry.bodyContent|length %}
     {% set customdescription = entry.bodyContent.type('text').one()|striptags|slice(0, 155) %}
  {% endif %}
  
  ```
  
  Which was manipulating for the code below. I resolved by using the clone option in my header like below:
  
  ```
  {% set bodycontent = entry.bodyContent %}
  {% if bodycontent|length %}
     {% set customdescription = clone(bodycontent).type('text').one()|striptags|slice(0, 155) %}
  {% endif %}
  
  ```
  
  **Tags:** matrix, craft3
  
  > **Comments:**
  > **username_1**: Do you receive the correct blocks when you append a `status(null).enabledForSite(false)` to the query?  
  > **username_0**: Thanks - but that made no difference - just my text blocks displayed again.  
  > **username_1**: Then there must be something wrong at some other point in your code. Maybe you manipulate those variables before? If it's visible in the CP it must be accessible  
  > **username_0**: It was working fine in Craft 2 - I've tried just outputting directly on the page as opposed to the above code which is in an include - but still getting the same. {{ entry.bodyContent|length}} is still only dislaying 2.  
  > **username_1**: You can get the raw sql and check if there are certain conditions attached that doesn't match via `ElementQuery.getRawSql()`  
  > **username_0**: see update in question - see a bit in query `AND ('matrixblocks'.'typeId'='3')`  
  > **username_1**: As I said you manipulate your query at some point. You either need to use the copy function or reset the property  
  > **username_0**: Ok - in my header at the top to get a metadescription I have `{% set customdescription = entry.bodyContent.type('text').one()|striptags|slice(0, 155) %}` if I comment that out all blocks are displayed - thanks  
  > **username_0**: Do you want to add that as an answer?  
  > **username_2**: Just want to say this comment / thread has saved me such a headache - i couldn't work out why my matrix blocks were not being output correctly, and going round in circles! sure enough i was doing some manipulation to the query elsewhere.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-11. Score: 2 | Accepted answer
  
  If you manipulate your query somewhere else in the code those properties will not reset after you execute it. You'll either reset the properties (for example `query.typeId(null).all()` or you need the `clone` [function](https://docs.craftcms.com/v3/changes-in-craft-3.html#cloning-element-queries)
  
  
  ---
  
  