Skip to main content
tagging as d7. distinguish from drupal8 entityquery
Source Link

How to use EntityQueryEntityFieldQuery with a simple text field?

I have a content type called foo and it has a textfield called field_bar. I have one that has a value set to baz.

I'd like to use the EntityQueryEntityFieldQuery object to find all foos that have field_bar with the baz value.

$nodeQuery = new EntityFieldQuery();
  $nodeQuery->entityCondition('entity_type', 'node', '=')
    ->entityCondition('bundle', 'foo') 
    ->fieldCondition('field_bar', 'value', '12345', '=');

The problem is that I get no results or error back. If I remove the fieldCondition, I get all foos including the one I am looking for.

As the documentation is vague and only for experts, I googled a lot, but can't find any reason for my query not returning my node.

I also tried with

->fieldCondition('field_bar', 'value', array('12345'), '=');

to see if that matters, but its the same. I dd-ed the $nodeQuery but can't see the executed SQL.

Is there anything special with textfields?

How to use EntityQuery with a simple text field?

I have a content type called foo and it has a textfield called field_bar. I have one that has a value set to baz.

I'd like to use the EntityQuery object to find all foos that have field_bar with the baz value.

$nodeQuery = new EntityFieldQuery();
  $nodeQuery->entityCondition('entity_type', 'node', '=')
    ->entityCondition('bundle', 'foo') 
    ->fieldCondition('field_bar', 'value', '12345', '=');

The problem is that I get no results or error back. If I remove the fieldCondition, I get all foos including the one I am looking for.

As the documentation is vague and only for experts, I googled a lot, but can't find any reason for my query not returning my node.

I also tried with

->fieldCondition('field_bar', 'value', array('12345'), '=');

to see if that matters, but its the same. I dd-ed the $nodeQuery but can't see the executed SQL.

Is there anything special with textfields?

How to use EntityFieldQuery with a simple text field?

I have a content type called foo and it has a textfield called field_bar. I have one that has a value set to baz.

I'd like to use the EntityFieldQuery object to find all foos that have field_bar with the baz value.

$nodeQuery = new EntityFieldQuery();
  $nodeQuery->entityCondition('entity_type', 'node', '=')
    ->entityCondition('bundle', 'foo') 
    ->fieldCondition('field_bar', 'value', '12345', '=');

The problem is that I get no results or error back. If I remove the fieldCondition, I get all foos including the one I am looking for.

As the documentation is vague and only for experts, I googled a lot, but can't find any reason for my query not returning my node.

I also tried with

->fieldCondition('field_bar', 'value', array('12345'), '=');

to see if that matters, but its the same. I dd-ed the $nodeQuery but can't see the executed SQL.

Is there anything special with textfields?

Tweeted twitter.com/#!/StackDrupal/status/439755956671750144
API link.
Source Link
mpdonadio
  • 38.1k
  • 8
  • 89
  • 142

I have a content type called foo and it has a textfield called field_bar. I have one that has a value set to baz.

I'd like to use the EntityQueryEntityQuery object to find all foos that have field_bar with the baz value.

$nodeQuery = new EntityFieldQuery();
  $nodeQuery->entityCondition('entity_type', 'node', '=')
    ->entityCondition('bundle', 'foo') 
    ->fieldCondition('field_bar', 'value', '12345', '=');

The problem is that I get no results or error back. If I remove the fieldCondition, I get all foos including the one I am looking for.

As the documentation is vague and only for experts, I googled a lot, but can't find any reason for my query not returning my node.

I also tried with

->fieldCondition('field_bar', 'value', array('12345'), '=');

to see if that matters, but its the same. I dd-ed the $nodeQuery but can't see the executed SQL.

Is there anything special with textfields?

I have a content type called foo and it has a textfield called field_bar. I have one that has a value set to baz.

I'd like to use the EntityQuery object to find all foos that have field_bar with the baz value.

$nodeQuery = new EntityFieldQuery();
  $nodeQuery->entityCondition('entity_type', 'node', '=')
    ->entityCondition('bundle', 'foo') 
    ->fieldCondition('field_bar', 'value', '12345', '=');

The problem is that I get no results or error back. If I remove the fieldCondition, I get all foos including the one I am looking for.

As the documentation is vague and only for experts, I googled a lot, but can't find any reason for my query not returning my node.

I also tried with

->fieldCondition('field_bar', 'value', array('12345'), '=');

to see if that matters, but its the same. I dd-ed the $nodeQuery but can't see the executed SQL.

Is there anything special with textfields?

I have a content type called foo and it has a textfield called field_bar. I have one that has a value set to baz.

I'd like to use the EntityQuery object to find all foos that have field_bar with the baz value.

$nodeQuery = new EntityFieldQuery();
  $nodeQuery->entityCondition('entity_type', 'node', '=')
    ->entityCondition('bundle', 'foo') 
    ->fieldCondition('field_bar', 'value', '12345', '=');

The problem is that I get no results or error back. If I remove the fieldCondition, I get all foos including the one I am looking for.

As the documentation is vague and only for experts, I googled a lot, but can't find any reason for my query not returning my node.

I also tried with

->fieldCondition('field_bar', 'value', array('12345'), '=');

to see if that matters, but its the same. I dd-ed the $nodeQuery but can't see the executed SQL.

Is there anything special with textfields?

Source Link
jabal
  • 192
  • 1
  • 14

How to use EntityQuery with a simple text field?

I have a content type called foo and it has a textfield called field_bar. I have one that has a value set to baz.

I'd like to use the EntityQuery object to find all foos that have field_bar with the baz value.

$nodeQuery = new EntityFieldQuery();
  $nodeQuery->entityCondition('entity_type', 'node', '=')
    ->entityCondition('bundle', 'foo') 
    ->fieldCondition('field_bar', 'value', '12345', '=');

The problem is that I get no results or error back. If I remove the fieldCondition, I get all foos including the one I am looking for.

As the documentation is vague and only for experts, I googled a lot, but can't find any reason for my query not returning my node.

I also tried with

->fieldCondition('field_bar', 'value', array('12345'), '=');

to see if that matters, but its the same. I dd-ed the $nodeQuery but can't see the executed SQL.

Is there anything special with textfields?