Questions tagged [query]
The query tag has no usage guidance.
144
questions
4
votes
3
answers
923
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).
...
4
votes
1
answer
3k
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 ...
4
votes
1
answer
924
views
Optimizing pagespeed
I'm not sure what is the cause for this page rendering so slow.
I thought it was the image transforms but I've removed them and still it's really slow to render.
Page in question: http://dharmaavenue....
3
votes
2
answers
4k
views
How to query an entry by a custom field in Craft 3
How do you query an Element by a custom field in Craft 3?
My first try, according to craftcms/docs was:
$country = Entry::find()
->section('countries')
->where(...
3
votes
2
answers
880
views
Most efficient way to check if a section has any active entries
Just wondering what the most efficient way to check whether a section has any entries or not. Based on this, I'm showing some content. The content doesn't take any information from the entries in the ...
3
votes
1
answer
1k
views
Query entries between two values
I am trying to query entries (scripts) when a custom expiration date field is within a certain range.
These questions/answers helped me get as far as I am, but I'm still stuck: Advanced query/filter ...
3
votes
2
answers
2k
views
Searching multiple queries using CraftCMS search function
As you can see in the code below I'm currently searching for the keyword but how can I make it so it picks up on entries that have a matching keyword, location & salary or if they don't fill out ...
3
votes
1
answer
442
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 ...
3
votes
1
answer
1k
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!
...
3
votes
1
answer
76
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, ...
3
votes
1
answer
334
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 ...
2
votes
2
answers
645
views
Element query for specific fields
Can a return schema be specified for entry queries? I'd only like the titles instead of the whole entry.
2
votes
2
answers
1k
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 ...
2
votes
2
answers
602
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()->...
2
votes
1
answer
295
views
List Only Available Times/Dates in Solspace Calendar
I have the following code that will output the UNAVAILABLE (previously booked) times of a Target Date. How would i edit this to output (in 30 minute increments) only the AVAILABLE times with Solspace ...
2
votes
1
answer
150
views
How to get column name of an entrie's field
I want to query some entries in a section.
I am able to write a query using a GET Param as a filter on the title field.
If I want to query a custom field however I need to know the precise column ...
2
votes
1
answer
31
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.
...
2
votes
1
answer
286
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 = ...
2
votes
2
answers
68
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 ...
2
votes
2
answers
656
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 )....
2
votes
1
answer
180
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 ...
2
votes
2
answers
108
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 ...
2
votes
2
answers
789
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
1
answer
268
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
1
answer
174
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.
...
2
votes
1
answer
917
views
Searching for any keyword in query
I have the following text search input field:
<form action="{{ url('search') }}">
<input type="search" name="q" placeholder="Search">
</form>
I would like to search each ...
2
votes
2
answers
830
views
Getting Unique entries?
I am querying data using the code below. In the database, there are duplicate entries for 'title', how can I get distinct values?
$criteria = craft()->elements->getCriteria(ElementType::Entry);
...
2
votes
1
answer
169
views
How to Check All Users against UserGroup
How can i check if ANY users exist in a particular User Group? I know how to check the current user but not ALL users.
2
votes
1
answer
106
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 ...
2
votes
1
answer
57
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't ...
2
votes
1
answer
40
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....
2
votes
1
answer
357
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 ...
2
votes
1
answer
46
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.
2
votes
2
answers
138
views
How 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.
2
votes
1
answer
172
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 ...
2
votes
1
answer
238
views
Sum with a group by Author
I am trying to build a leaderboard page, and I'm having difficulties finding a way to group the entries by Author.
I was able to create a plugin to get the sql sum function in there, but I now need ...
2
votes
1
answer
118
views
Query for enabled categories
In a template, I want to show only enabled categories. I can't figure out how to filter the returned categories by only enabled ones, without doing it in the for loop.
This works:
{% for category in ...
2
votes
2
answers
163
views
Plugin development - Querying related data
I am working on a Craft plugin.
I have a main entities are 'Courses' and 'Entries'. If I click on an Entries in the CMS there is an option to select and associated 'Course'.
In my controller I can ...
2
votes
1
answer
21
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
1
answer
78
views
How can I retrieve older versions of a custom entry type in bulk?
I am building an API that returns instances of an entry type. Only authenticated users can access the API. There are different tiers of user - paid and free. Free users can access the API, but the ...
2
votes
0
answers
334
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 ...
2
votes
0
answers
130
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
2
answers
313
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
3
answers
99
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('...
1
vote
2
answers
279
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
2
answers
151
views
Cannot pass where Params to query with Twig variable
I have a text field that has three values on new lines.
E01001667
E01001668
E01000779
I want to use these for a query that looks like this:
{% set mylsoas = craft.entries.
section('imdData')
....
1
vote
1
answer
416
views
Get entries with a specific post date
I'm having absolute brain fog right now.
I'm trying to show a list of entries with a given postDate
{% set startDate = startDate ?? now|date('Y-m-d') %}
craft.entries
.section(['jobs', '...
1
vote
2
answers
240
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,
...
1
vote
2
answers
867
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
1
answer
43
views
Find First Entry That Matches Current Category
I need help. I am creating a category listing which I have working great. The next step is where I'm struggling a bit as I can't seem to query the related entries on a loop basis.
For each "...