Questions tagged [query]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2
votes
1answer
23 views

Using 'or' within query parameters

I have an entry which shows related events, based on the entry category, at the bottom. These events all have a start date and an end date - the end date is required, if the event is only one day, ...
1
vote
1answer
38 views

Remove duplicate text from query results

I have written a query to select all categories for a certain entry. In this case, the category is called "Key Stage" and each one is written "Key Stage 1", "Key Stage 2" ...
2
votes
2answers
182 views

Get array of titles instead of whole collection of entries' attributes

I know that to get the entries I can do: craft.entries.all() but instead of getting the whole collection of entries, I would like to get an array of titles from those entries (or any other field). ...
1
vote
2answers
87 views

Pass parameters to element query as array - in PHP

In Twig, we can do this like this: craft.entries({ id: 11, relatedTo: 22, }) But in PHP code, this does not work: \craft\elements\Entry::find( [ 'id' => 11, ...
0
votes
1answer
44 views

Find related entries by specific position in the entries field

I'm looking for a way to limit a reverse relations query to only match the first selected entry in an entries field. Some context: I have two entry types, institutes and offers. Offers have an ...
1
vote
0answers
32 views

Order element query by number of related categories

I'm building an entry template that displays related entries to the current entry. To be related, an entry needs to be the same type as the current entry and share at least one category in one of two ...
1
vote
1answer
26 views

Get raw/unformatted field values?

Is there a way to get raw/unformatted values for a field before they're passed to the field's normalizeValue function? That is, get the value close to how it's stored in the database? I haven't found ...
0
votes
0answers
37 views

how to retrieve any/all related entries?

I have list of banks(institutions) that each one has branches. I'm using GraphQL API. By the bellow code I can get the branches with associated bank(institutions): query branches { entries(limit: ...
0
votes
0answers
27 views

GraphQL API query to load all related data

How to write a query to load entries with its category or any other related data. For example I have cars that related to the BMW category. How I can access the category data in the query that fetch ...
0
votes
0answers
9 views

Query date field, timezone not taken into consideration

I'm trying to query a custom table on a DATETIME field. My timezone is UTC+2 and the dates stored in the database are UTC. shiftEnd in database: note that the shifts ends at 08:35 UTC, in my timezone ...
1
vote
1answer
73 views

'and' & 'or' in the same entry query

I've been attempting to create an entry query that queries the same custom field twice. Basically I want to check if a custom field is between 2 numbers OR if it is empty. Currently I'm using this to ...
0
votes
0answers
33 views

Query Entry where number field is conditional to value

I am trying to get entries where a specific number field is bigger than the given value. But Craft is giving me the following response: Am i missing something or is this not supported for number ...
1
vote
1answer
87 views

Entry query returns all fields with NULL

When trying to query a specific single entry in a section I get back a result but all the fields inside that result are nulled. This {% set kundenmeinungen = craft.entries.section('unterseiten').slug('...
0
votes
0answers
69 views

Search Entries by Post Date

Is there a way to direct Craft to include entry.postDate in the search? I'm using a simple query to search entries. {% set entries = craft.entries.section('mySection').search('*' ~ query ~ '*').limit(...
1
vote
1answer
97 views

Element API: Get Entries Related to Category with Query Parameter

I'm using the Element API Plugin to create an API, with which I want to get entries related to one category, but dynamically with the category set in the Url. What I have so far in the config/element-...
2
votes
1answer
18 views

Search Filters Results Unexpectedly

This question is related to: SuperTable Returning Unexpected Results w/ Template, which is still unresolved. In essence, Im trying to return the results of a Supertable at two different points in my ...
2
votes
1answer
96 views

How to structure data: Solo Events (Lectures) and Group of Events (Conferences)

I am working on my first craft project and am wondering how to create the following data structure: I have a page with a large archive of solo-events (lectures, discussions etc). I think I will use a ...
1
vote
1answer
192 views

Sprig - Filter entries by custom field checkbox values, separate values as well as all values

I am having a question regarding Sprig. I do want to filter my entries for values that are defined in a dropdown field (example below is simplified). It does work to the point where I want to filter ...
0
votes
0answers
83 views

How can I use 'where' in an advanced search query?

I came across this handy tip for search queries on Twitter: https://twitter.com/nystudio107/status/1354815792638955524/photo/2 {% set entry = craft.entries({ section: 'blog', where: ['like', 'title', '...
2
votes
1answer
23 views

Query entries posted in the past month

I’m trying to show only entries for the created in the last month. I’ve taken this from the example in the docs but it ends up showing nothing. There’s 100% entries with a postDate in the last month. ...
0
votes
0answers
30 views

Hiding enclosing div if all matrix block fields are empty (although they do exist because of another language)

I have an entry with matrix fields. If I add blocks in the main language, but its fields only contain data in one language, the block query (the for loop) still finds these empty fields since they do ...
1
vote
1answer
67 views

Multiple relatedTo conditions using a combination of "and" and "or"

We're trying to make a filter that allows you to pick multiple items from 1 category, and multiple items from another category and return back all appropriate elements. We're in PHP land not twig so ...
0
votes
0answers
38 views

Output Entry with Super Table, Matrix, Table for Element API

I'm trying to output a table within a matrix of a SuperTable for element API. I fail to output $projectList, I keep getting the error 'Invalid argument supplied for foreach()' or 'Trying to get ...
1
vote
1answer
236 views

Craft 3 - Twig search query for entry with custom EntriesField containing disabled entry

I have a search form with 1 simple input (q) I also have 2 sections: SECTION-A & SECTION-B The search is for entries within SECTION A. The entry I'm searching for contains a custom entriesField ...
1
vote
1answer
13 views

Order entries by DATEDIFF

I'm trying to order the results of an entries query by the difference between two date fields but I can't seem to get it to work. Here is my query: {% set todaysStreamsParams = { section : 'films', ...
1
vote
1answer
68 views

Eager load commerce order data in custom ElementExporter for Users

I have a custom ElementExporter for users and I'd like to include commerce order data. The below code works, but it's a ton of queries. I don't have a ton of experience with SQL queries, how can this ...
1
vote
1answer
19 views

Is there a way to query for a list of values belonging to a specific field in a queryset?

For instance, if I wanted an array of all the titles belonging to a subset of entries that I wish to query. The way I know how to do this currently is like so: {% set titleList = [] %} {% ...
1
vote
1answer
2k views

GraphQL query entries by DateTime field between two dates

I am trying to query entries in GraphQL by custom DateTime field value. It works with the base String value like ">=2020-10-01", However querying between two dates like "['and', '>...
1
vote
1answer
40 views

Query entries with latest video field containing a URL

I would like to set up a query to find the latest news article that has a video attached to it ('video' is a matrix field with a block type that is also called 'video' and a field called 'videoUrl'). ...
1
vote
2answers
75 views

Order entries by multiple matrix date field

I have a section with trainings. In each training entry there's a matrix field where we add a new block with a training date, location, etc. So each training has multiple matrix blocks. When I run an ...
1
vote
1answer
34 views

Problem with SUM on Matrix blocks

I have some Matrix blocks where I need to sum one of the fields within, but I only want to sum it when another field within that block is or is not empty. {% set reimbursementAmount = craft....
0
votes
1answer
37 views

Query only Tags wich are not connected to a revision

I wrote a query like this: $query = (new Query()) ->select('COUNT(elements.id) as count, tags.*') ->from('relations') ->join('INNER JOIN', 'tags', '{{relations}}....
1
vote
1answer
124 views

Comparing matrix blocks by type and field value

I’m trying to do something, the answer to which should be as simple as searching a Matrix field value but that’s not working for reasons I can’t fathom. Setup I have a Matrix field called programme. ...
1
vote
2answers
109 views

Offset setting a limit?

If have this in a template: {% for mainLink in section.links.limit(4).all() %} {% endfor %} {% for secondaryLink in section.links.offset(4).all() %} {% endfor %} Which I thought would show the first ...
1
vote
0answers
207 views

Filter entries in GraphQL

I'm using Craft with Gatsby. I'd like to query a featuredpost, and filter that in my entries. I'm getting the featuredPost slug in gatsby-node, and passing that to createPage, to send a variable to my ...
1
vote
1answer
85 views

How do you eager load or join reverse relationships for entries?

So I have structures that are related in the follwing way: Locations has many Providers Providers has many Health Topics I know that I can eager load all Locations with related Providers and Health ...
1
vote
2answers
46 views

How can I display just the "lowest" categories assigned to an entry and not parent categories?

I have a category tree like this and I have an entry that has four categories A, A1, B, C2: A A1 A2 B B1 B2 C C1 C2 I want a query that ignores A and returns only A1, B, C2, because I don't ...
1
vote
1answer
37 views

Mass enable entries

I'm trying to set statuses to enabled in mysql. Around 150k entries. The tables are elements and elements_sites. Set status to 1. The query runs OK. In the cp is also everything fine but entries don'...
1
vote
1answer
68 views

Optimising search query

I was wondering if there is a better way to do a query like this, it takes a long time to execute and I know setting the parent variable is where there's a problem but am not sure of an alternative ...
1
vote
1answer
67 views

Advanced Search Filter

I am trying to complete an advanced search query with Smart Map, but I can't seem to quite get it. I tried to merge several URL parameters, and they seem to work fine except when it comes down to ...
1
vote
1answer
47 views

Get entries with related to selected categories and then group by category

Background: I have a listing overview page that lists teaching staff grouped by their department (A category group holds all departments). E.g. All Staff Members: -- Science -- Mrs Magnesium ...
1
vote
2answers
71 views

Querying across relationships in a template

I have two Sections on my site: Country and Alert. The Alert section has a relation with Country via an "Entries" field. An Alert represents something that is happening in a particular country for a ...
1
vote
2answers
574 views

How to get previous and next entry using the native GraphQL API?

How do I turn these Craft queries into a GraphQL one? // entry.twig entry.getPrev({ section: "contentHub" }) entry.getNext({ section: "contentHub" }) I want to get the previous and next entry using ...
1
vote
1answer
73 views

Simple user query with orderBy not working

Craft 3.3.13 This query does not order users correctly. {% set users = craft.users.groupId(3).orderBy('lastName asc') %} Bug?
2
votes
1answer
138 views

Excluding specific field value from search

I want to find all entries that match the title field where excludeFromSearch != 1 (is false). {% set query = 'and excludeFromSearch not 1 and ' ~ 'title:"' ~ "myValue" ~ '"' %} {% set results = ...
1
vote
1answer
362 views

In entries query, is there a way to check if matrix block is used?

I would like to get entries if a matrix field is used. Something like this: {% set query = craft.entries() .section('blog') .search('myMatrixField|length') .limit(10) %}
2
votes
2answers
575 views

Query entries by custom date field (for a particular year)

So I'm trying to get all entries that have a particular year assigned to a custom date field. (Could be any day/month in that year). The custom field is startDate and my attempt at a query - which ...
1
vote
1answer
46 views

Find Entries based on Field Values

I have a set of events I want to query based on user-input date times. How do I achieve something like this? {% set entries = craft.entries.section('events').minScheduleDate('>=', 'now')....
1
vote
1answer
182 views

User query in PHP does not work

I would like to get user query in my custom PHP plugin. According to this document, the code would be like this. https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#example $...
1
vote
1answer
79 views

Can I query based on a date field rather than the postdate?

I'm passing along a year as the yearQuery variable. Later in my template, I am doing this: {% set eventEntries = craft.entries .section('events') .eventStartDate('>=' ~ yearQuery) ....