Contentful logo

Contentful Community

Multiple Fields Inclusion

I’m trying to use the inclusion option for the content delivery API

client.getEntries({
content_type: ‘<content_type_id>’,
‘fields.<field_name_1>[in]’: ‘accessories,flowers’
});

My issue is that I need to do multiple inclussions, for that im trying to do the following:

client.getEntries({
content_type: ‘<content_type_id>’,
‘fields.field_name_1[in]’: ‘accessories,flowers’,
‘fields.field_name_2[in]’: ‘table,fork’
});

This returns fields that include values for both “field_name_1” AND “field_name_2”, logically, but what I need is “field_name_1” OR “field_name_2”, to not discard results that do not include one of the fields.

Is there a way around this? Any help is appreciated.

Hi @ernesto.frade,

For the case of an “OR operation”, this structure would indeed not work as it’s not currently available under our APIs.

Instead, what you should do is to perform two different requests and later process them separately or concatenate results. In your example, you’d send these two requests:

client.getEntries({
content_type: ‘<content_type_id>’,
‘fields.field_name_1[in]’: ‘accessories,flowers’,
});

and

client.getEntries({
content_type: ‘<content_type_id>’,
‘fields.field_name_2[in]’: ‘table,fork’
});

Let me know if that makes sense :slight_smile:

Thanks @gabriel, I was hoping there was a hidden doc I had not read. I considered this amongst other solutions but decided to reach out before. Appreciate the response.

Thanks.

@gabriel are there any plans to include “OR operation” in the near future ?
Will be joy! :slight_smile:

The need is like I need to get a list of items which are linked to a particular reference field and also by a set of tags

Like need a list of food items which are mango based and also with tags “sugarless, no preservatives, no artificial colors”
Reference field (many): mango
tags: sugarless, no preservatives, no artificial colors