This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » eZ Publish 5 Platform » Public API, Field Criterion search

Public API, Field Criterion search

Public API, Field Criterion search

Friday 14 June 2013 5:15:12 pm - 6 replies


I'm trying to access all objects of a given Content Type that contains a field with a given value.

Here is the way I do that.

    // namespaces are imported, no problem with that
    $query = new Query();
    $query->criterion = new Criterion\LogicalAnd(
        new Criterion\ContentTypeId( 4 ),
        // EmailingStatus::IN_PROGRESS is an integer constant class attribut
        new Criterion\Field( 'status', Criterion\Operator::EQ, EmailingStatus::IN_PROGRESS ),
    $results = $this->searchService->findContent( $query );
    foreach ( $results->searchHits as $sh )
      var_dump( EmailingStatus::IN_PROGRESS );
      var_dump( $sh->valueObject->getFieldValue( 'status' )->value  );
      // Rest of code. Not relevant

The result says that EmailingStatus::IN_PROGRESS as the value '5' and the 'status' field of the first content object returned by the query is '3'. This should not happend due to the second Criterion.

I cannot find out what is the problem here. Any help ?


Modified on Monday 17 June 2013 9:50:31 am by Nicolas ---

Saturday 15 June 2013 11:45:05 am

very nice post

Monday 17 June 2013 6:54:47 am

The use case is simple : we need to properly alter the behavior of the LegacyKernelController's indexAction

Tuesday 18 June 2013 4:43:40 pm


I had a similar problem : a content being return when it shouldn't.

And I found the problem : the search service is searching EVERYWHERE, so it was returning older versions of the object, even if it didn't match the criterion :/

So maybe add a status criterion in your query :

new Criterion\Status(array(Criterion\Status::STATUS_PUBLISHED));

Hope it helps.

Modified on Wednesday 19 June 2013 10:32:22 am by Julien Montavit

Tuesday 18 June 2013 5:02:42 pm

The Field versioning issue was reported a few days ago, and I don't think Status will help you here.

Please test patch and provide feedback on the Pull request:

Modified on Tuesday 18 June 2013 5:03:48 pm by André R

Wednesday 19 June 2013 11:16:57 am

Hi, thanks for the response.

I'm on my last day working on eZ Publish 5, but I will try to find a moment to build a test environment.

Wednesday 19 June 2013 12:50:50 pm

You can aslo try to adapt the patch directly on your local installation, if you have 5.1 / 2013.05 / 2013.06 it should apply quite cleanly. 

Modified on Wednesday 19 June 2013 12:57:17 pm by André R


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from