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)

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 %}


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 %}
  • Do you receive the correct blocks when you append a status(null).enabledForSite(false) to the query? Jun 9 '18 at 23:48
  • Thanks - but that made no difference - just my text blocks displayed again.
    – mmc501
    Jun 10 '18 at 20:42
  • 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 Jun 11 '18 at 5:15
  • 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.
    – mmc501
    Jun 11 '18 at 5:17
  • You can get the raw sql and check if there are certain conditions attached that doesn't match via ElementQuery.getRawSql() Jun 11 '18 at 5:18

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.