Questions tagged [query]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
10 views

GraphQL query order entries by Lightswitch and DateTime field

I have an entries with the "highlighted" lightswitch that puts entry on top of the result list when enabled, also I need to sort items by post date. So, in the end there should be the ...
1
vote
1answer
23 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
15 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
44 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
30 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
37 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 ...
0
votes
0answers
23 views

Filter entries by specific child field of a field?

Is it possible to create a query which filters the results by a child of a field? For example I have an address field which has multiple fields amongst other a country field. I would like to fetch the ...
0
votes
0answers
8 views

Adding a specific field to search() parameter that contains an object

I'm currently running a search which contains an object {query:query, subLeft: true, subRight: true} {% set query = craft.request.getParam('q') %} {% set entries = craft.entries.section('example')....
1
vote
1answer
20 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
21 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
53 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. ...
0
votes
0answers
24 views

Filter Entry Query by Category

I'm making a staff page. The entries are in the section 'people'. There are four types of staff - leadership, wardens, staff, safeguarding - so there is a category field for each 'staffCategory'. That ...
0
votes
0answers
58 views

SQLSTATE[HY000]: General error: 7 number of parameters must be between 0 and 65535

{% set entryIds = craft.entries ({ section: 'locations' }).ids() %} {% set cities = craft.categories ({ descendantOf: category, ...
1
vote
2answers
31 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 ...
0
votes
0answers
46 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 ...
0
votes
0answers
26 views

How to write multiple operator condition in where statement of db query

$query = (new Query()) ->select([]) ->from(['{{%custom_table}}']) ->where(['<=','firstDate', now()]) ->all(); In craft3, I want to add multiple ...
0
votes
0answers
33 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
1answer
23 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
30 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
54 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 ...
0
votes
0answers
13 views

Sort entry query by their table of values if said values are in a separate array of values

Morning (in the UK at least) - I'm trying to sort/order/filter an entry query by an array of values. The array is a list of IDs (e.g. [2,7,8]), and inside each entry is a table with a list of IDs that ...
0
votes
0answers
19 views

Front End get category group from uid

I have a form on the front end which has a category field. I want to display all the options from the category group, by obtaining the categories from the category group. When i dump the properties ...
0
votes
0answers
25 views

Query Events by Matrix Field using Where clause

I am new to Craft CMS. I am able to get a list off all upcoming events with: $events = Calendar::getInstance()->events ->getEventQuery( [ 'calendar' => 'sample_calendar', ...
1
vote
1answer
47 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 ...
0
votes
0answers
101 views

Custom Elements + Joins

I'm having a bit of trouble wrapping my head around an SQL issue with a custom Element. One column in my Element's table—for the case of this question, let's call it myplugin_things—has a foreign key ...
1
vote
1answer
34 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
35 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
262 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
36 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
50 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
153 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
219 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
40 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
90 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
49 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) ....
1
vote
1answer
46 views

Filter and sort Commerce products based on Matrix blocks

We have a website that uses Craft CMS v3.1.28 and Commerce v2.1.6.1. The below logic is implemented within a plugin and we're prepared to do custom implementations aka. prepared to go deep! I would ...
2
votes
2answers
49 views

Best practice for year based paging

Is there a best practice for a paging based on the years of entries (instead of page numbers)? Example: I have 3 records with post dates 2019-01-01 2018-01-01 and 2016-01-01. So my paging should look ...
1
vote
0answers
74 views

Database Query in debugger consistently showing over 2000ms

In trying to optimize my Craft 3 site, I have discovered that it's apparently taking longer than expected to query my database. The duration for the apparent culprit is typically between 1900 and ...
2
votes
1answer
23 views

Paginate entries ordered by a custom date field

I'm trying to paginate a bunch of events based on their start date. The order part is working correctly, but each consecutive page just loads the exact same entries. My code: {% set events = craft....
1
vote
0answers
180 views

Advanced queries with Super Table

I have three channels: Events, stages and artists. An artist is added to a timetable super table field in the stage channel. In the event, I have a stages field where I select stages. Events also ...
1
vote
0answers
67 views

What's the most performant way to get reverse related entries within an Element Query?

What's the most performant way to get reverse related entries within an Element Query? Here's a contrived example of this. I have thousands of "book" entries and thousands of "collection" entries. I ...
1
vote
2answers
141 views

Get entries after a certain time

I am trying to get all entries from my events section in Craft 3 that occur after 17:00. My current code is: {% set events = craft.entries.section('events').eventStartTime('>= ' ~ '17:00'|time )....
1
vote
0answers
122 views

How to get url from related entry in another site

I'm relating entries from another site in my installation, and I'm having issues getting the correct URL for the entry. This is an example of what I currently have: {% set carouselEntries = entry....
3
votes
1answer
158 views

How to query entries written in a specific locale? (Craft 3)

In Craft 2 you used to be able to do something like {% set entries = craft.entries.section('something').locale('de') %} but .locale() has been removed and there's nothing similar in the docs that I ...
1
vote
0answers
53 views

Order entries by a matrix field category

I have a lot of trouble in understanding the database/model structure and how to work with the query builder. I tried playing a bit with leftJoins but i cannot seem to make complex queries in craft 3. ...
1
vote
1answer
128 views

Connect to an external database from a Craft 2.x plugin

I recently saw a very helpful post about how to connect to an external database from a Craft plugin and I wanted to confirm I understood the implementation correctly. On this response the author ...
2
votes
2answers
425 views

How to include asset fields in query in php?

I am trying to figure out how to return asset field(s) in a PHP entry query. Also if I could learn how to return "custom fields" when returning an Object that would be great too! Right now I am having ...
2
votes
1answer
201 views

exclude array of entry types in query

Here is my query: {% set resources = craft.entries({ section: 'resources', type: 'not caseStudyLanding' relatedTo: filterParams, orderBy: 'postDate desc' }) %} I would like to ...
1
vote
1answer
23 views

Is there a query parameter to get categories that are related to anything else?

I'm looking for a way to query all categories that have at least one relation. I'm not looking for the relatedTo() parameter, which would give me categories related to something specific. Basically, ...
2
votes
1answer
32 views

How to show entires from past 12 months?

I need to display entries from the past 12 months. I'd like to create an entry query and set the timeframe of the entries I need.