Questions tagged [query]
The query tag has no usage guidance.
86
questions
1
vote
1answer
24 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
23 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 ...
0
votes
0answers
27 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
18 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
24 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
53 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)
%}
0
votes
0answers
8 views
Output category hierarchy in Element API
I am looking to output categories in a level hierarchical format.
I have multiple categories, with different levels of categories.
Entries can be related to different levels of those categories.
...
2
votes
2answers
54 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
32 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
44 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
28 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
39 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 ...
1
vote
2answers
45 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
38 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
15 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
90 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
47 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
69 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
70 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....
2
votes
1answer
60 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
43 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
66 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
238 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
95 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
22 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
26 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.
1
vote
1answer
88 views
where command sql query not working
My problem is that I can't update the specific $userId. have the values I've selected. I also get an error:
Call to a member function where() on integer
I just started to learn Craft. It can be ...
1
vote
1answer
48 views
Get to get all users with active Commerce 2 subscription
How do I get all the users with an active subscription in Commerce 2? I want to be able to filter entries by subscribed users.
1
vote
3answers
72 views
Returning entries that contain both categories
I'm creating a filter and would like to return entries that must contain multiple categories (and behavior, not or). A sample url would be /events?cat=2,3.
{% set eventCat = craft.request.getParam('...
2
votes
1answer
391 views
How to query entries by field values
I have some entries with a multi-select field called "gallery". We can choose many images to this field.
I have a given image, how can I query entries whose "gallery" contains this given image? Thx!
...
1
vote
1answer
45 views
Payment Method and Discount elements query by ID in Twig
In Craft 2, is it possible to query a specific element by ID in Twig? They aren't mentioned in the docs.
I was trying things like these but without success:
{{ craft.commerce.paymentMethods.id(1)....
2
votes
1answer
110 views
Showing entries for light switch [duplicate]
So I have three light switches on my blog: 'featured', 'required reading' and 'skills'.
I got the featured section to work with this code:
{% for entry in craft.entries
.section(['etiquette', '...
2
votes
1answer
86 views
Where to put where() for a query looking for a lightswitch field
Struggling with syntax here. I'm trying to query entries in the "resources" section, ordered by postDate desc, limit 1 and that also has the lightswitch "featured" as true. Here is what I have.
...
1
vote
1answer
79 views
How do multiple date queries differ between Craft 2 and 3
After spending a lot of time solving this for myself I thought I'd share it.
In my Craft 2 template I had this query:
{% set result = craft.entries({
section: 'events',
eventDate: ['and', '&...
1
vote
2answers
150 views
Where should the .all() be placed in Craft 3
I'm confused, I have ended up with 2 similar queries in a template after converting them from Craft 2.
{% set events = craft.entries()
.section('events')
.eventDate('>' ~ now|date('Y-m-d H:...
1
vote
1answer
107 views
Joining sections (Channel) to query based on a related item attribute
I've been trying this for a while now, so might have read this before. Sorry about that, I'm struggling really hard to get this right. At first I tried (wrongly) with the eager load features.
I have ...
1
vote
0answers
21 views
Paginate entries based on related status
So, let's assume I have two channels. events and movies, being events the screening time of each movie. In the admin, in the event entry, you can select one movie.
The movie could be disabled. The ...
2
votes
1answer
109 views
How to get the unverifiedEmail value of a user after a change email request?
The currentUser.unverifiedEmail variable, which is public, is always empty on front end even after email change.
I thought it was a bug. I contacted Craft support about this, and here is Brad's ...
1
vote
0answers
49 views
Check the field type of all the attributes of an entry
Here's the whole picture:
I'm trying to make an API endpoint which should output everything from an entry:
First I did this:
public function transform(Entry $entry)
{
return $entry-...
1
vote
1answer
165 views
Matrix block fields returning NULL when using MatrixBlock query
$blocks = MatrixBlock::find()->relatedTo($entry)->all();
The above returns the correct blocks but all fields are returned as NULL.
I've read over at GitHub that we need to specify a fieldId ...
2
votes
2answers
198 views
Element Query matrixfields where
I'm trying to query entries in a section where the (activities) entry has an item in a matrix field timeSlots -> timeSlot -> startDate.
The startDate must be >= NOW().
$query = Entry::find()->...
1
vote
1answer
427 views
Craft query Matrix blocks in twig
Is it possible to query elements of type MatrixBlock in Twig like other elements? You can get entries with
{% set entries = craft.entries.all() %}
Is there something similar available for Matrix ...
1
vote
1answer
133 views
Difference between chained and batch element queries?
I apologize if this has been asked or addressed already, but I have a question concerning Element Queries. The docs show two possible ways:
Chained Methods
{% set query = craft.entries()
....
1
vote
1answer
52 views
How to get entries with or
it is possible to do like this:
$users = Entry::find()
->userLevel('>3')
->or group('admin')
So in database level,the sql will go like this:
select * from users
where users.userLevel ...
1
vote
1answer
83 views
Query entries from two sections, check date field for one section and include pagination
I'm having a page that shows entries from two sections: news and events.
The page has the following layout:
All current event entries
Current event entry 1
Current event entry 2
All upcoming event ...
1
vote
1answer
214 views
Query section entries based on start/end date and type
I'm having the following layout on a page: a messages page that shows events and news that are grouped in a section called messages. The page starts with current events, then upcoming events and ...
0
votes
1answer
378 views
Get all entries with linked entry in entries field
I have a channel called 'projects'.
This channel has two entries fields:
relatedThemes
relatedAreas
What I want to do is perform a search query which filters all projects where the relatedThemes ...
4
votes
1answer
1k views
Craft 3: Get Data from a custom Table via createCommand()
In Craft 2 you could creat a query with:
craft()->db->createCommand()->select() .... etc.
But in Craft 3 there is no select() Method in Craft::$app->db->createCommand().
Am I ...
1
vote
1answer
1k views
Relational query get error “Getting unknown property”
I built up a plugin and inside the plugin I created the relation between Entry and Section using ActiveRecord, like below:
In SectionRecord :
class SectionRecord extends ActiveRecord
{
public ...
1
vote
1answer
395 views
How to build complex Element Criteria?
How to fetch Elements with a complex DB query?
E.g. with some nested AND/OR conditions or just apply two conditions to one field?
For example my Elements have a field eventDate. I want to fetch all ...