I have the following query:

$query = \Drupal::entityQuery('node')
            ->condition('type', 'case_study')
            ->condition('status', '1')
            ->sort('changed', 'DESC')

$query->condition('title', "%QUERY%", "LIKE");

$nids = $query->execute();

This works fine, however it obviously only searches on the title of the node. My case study nodes' fields are structured like this

- Case Study
    - title
    - field_page_banner
    - ...
    - field_rows <-- this is my paragraphs field

The paragraphs can contain multiple types and are chosen by the user when creating the content.

I want to be able to alter my query so that it searches the content of the paragraphs. For example, if the user adds a 'Rich Text' paragraph type, it will search the text.

This works fine for the built in search functionality, I just want to create a page of case studies with search functionality.

I am using Drupal 8.2.4 and Paragraphs 8.x-1.0.


The \Drupal::entityQuery object doesnt support JOINs I believe: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Query%21QueryInterface.php/interface/QueryInterface/8.2.x

If it did you could Join onto the Paragraph bundle and LIKE across that all you want.

I recommend the following approach with Views, a small chance exists it may not work:

  • Create a View of your case study Nodes
  • add a relationship to the Paragraph bundle (if needed)
  • assure the field list for the View includes title and field_rows (you can Exclude field_rows from showing in your view if you want).
  • add a Grouped Filter and Expose it and select it to use your title and field_rows values.

That should do the trick...

  • This sounds like it might be exactly what I want, however I'm stuck at the Grouped Filter, is this the same thing as the normal Filter Criteria or Contextual Filters options? Or is this something different?
    – SteveEdson
    Jan 6 '17 at 16:47
  • A Group Filter is an option when adding a Filter Criteria. You must have already added the fields you want to group upon to your View.
    – tenken
    Jan 7 '17 at 3:43
  • Ah I see, I'm not getting a Group Filter option, could it have been renamed to Combine fields filter? Or am I missing a module?
    – SteveEdson
    Jan 9 '17 at 8:31

After keep on testing and write the query i found out it do support join for paragraph. Below is my query

$query = \Drupal::entityQuery('node'); $query->condition('field_content_type_paragraph_name.entity.field_paragraph_field_machine_name.target_id',"NODE ID HERE"); $entity_ids = $query->execute();

Here is the generated query

[node__field_content_type_paragraph_name] => Array
                        [join type] => INNER
                        [table] => node__field_content_type_paragraph_name
                        [alias] => node__field_content_type_paragraph_name
                        [condition] => node__field_content_type_paragraph_name.entity_id = base_table.nid
                        [arguments] => Array

                [paragraphs_item] => Array
                        [join type] => LEFT OUTER
                        [table] => paragraphs_item
                        [alias] => paragraphs_item
                        [condition] => paragraphs_item.id = node__field_content_type_paragraph_name.field_content_type_paragraph_name_target_id
                        [arguments] => Array

                [paragraph__field_paragraph_field_machine_name] => Array
                        [join type] => INNER
                        [table] => paragraph__field_paragraph_field_machine_name
                        [alias] => paragraph__field_paragraph_field_machine_name
                        [condition] => paragraph__field_paragraph_field_machine_name.entity_id = paragraphs_item.id
                        [arguments] => Array


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.