Questions tagged [query]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4
votes
1answer
2k 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
1answer
863 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
2answers
3k 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
2answers
803 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
2answers
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
1answer
275 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 ...
2
votes
2answers
166 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). ...
2
votes
2answers
530 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
2answers
473 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
1answer
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 ...
2
votes
1answer
271 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
1answer
22 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
1answer
130 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
2answers
59 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
1answer
857 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! ...
2
votes
2answers
593 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
202 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
152 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
1answer
762 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
2answers
687 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
1answer
164 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
1answer
94 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
1answer
34 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
1answer
286 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
1answer
41 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
2answers
120 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
1answer
148 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
1answer
211 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
1answer
101 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
2answers
158 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
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
72 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
0answers
268 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
0answers
110 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
101 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
3answers
90 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
2answers
218 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
2answers
80 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
2answers
537 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
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
2answers
69 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
144 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
1answer
204 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
841 views

Merge two queries of entries ordered by publication date

I got a section called news which contain 2 types of entries: news and press. Those entries are linked with 2 different categories : news entries have category newsType and press entries have ...
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 ...
1
vote
1answer
65 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-...
1
vote
1answer
176 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 ...
1
vote
1answer
218 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
1k 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
39 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'). ...