Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

The tag has no usage guidance.

1
vote
1answer
18 views

Showing entries for light switch

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', '...
1
vote
1answer
13 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
18 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
54 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
24 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 ...
0
votes
0answers
13 views

Logging executed queries in Craft 2

I am trying to create a Craft 2 plugin that will enable me to log executed queries. Unfortunately I am no where, I can't even find any reading material. I tried extending the Yii CFileLogRoute ...
1
vote
0answers
12 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
19 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
14 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
18 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 ...
1
vote
2answers
43 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
106 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
48 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() ....
0
votes
0answers
40 views

Craft 2 Query Builder from SQL Help

I am trying to convert a plain SQL query I have into query builder. I am getting close, both subqueries seem to be working independently in the query builder syntax but I am struggling to get the ...
1
vote
1answer
26 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
28 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 ...
0
votes
0answers
19 views

Getting total results count (and/or using pagination) after ElementCriteriaModel is converted to dbCommand via buildElementsQuery

I've implemented a custom search plugin that generates an ElementCriteriaModel, converts it via buildElementsQuery and then adds additional SQL SELECTs (for geo searching over latitude/longitude ...
1
vote
1answer
41 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
36 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 ...
2
votes
1answer
118 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 ...
0
votes
0answers
25 views

Optimize the conditional

How do I optimize/improve this specific conditional? There are around 40k categories and it takes forever to load the page. {% if category.level == 1 %} {% include '_clinics/categories/state' %} {...
1
vote
1answer
199 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
84 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 ...
1
vote
1answer
47 views

Search and link to Entries Matrix Field

I'm trying to create somewhat of a clever search for which only searches through certain pages of my site. At the moment, it can search those pages, but instead of the result returning the page name, ...
1
vote
1answer
61 views

Select query question

I am trying to do the following with craft.entries but I think it may not be possible without a plugin. I have 9 categories with related entries on all of them. I would like to get the latest ...
1
vote
0answers
49 views

Category counts for query results

I'm trying to display results from a search. I want to display the categories represented by the search results and the entry count for that category. Think of how Amazon's "refine results" sidebar ...
1
vote
1answer
81 views

MySQL CPU pegged on specific query

Very similar (almost exact) to this question: Poor performance on midsized site / Queries without index? CPU keeps getting pegged to 100% for MySQL, which makes the admin interface very slow (the ...
1
vote
0answers
33 views

Combine multi-tiered loop into a single query (via plugin)

I am very new to Craft so forgive me if I knacker how this is asked. I have a set of IDs in an array. I try sending that into a relatedTo statement (which yields a series of locations...see below ...
1
vote
1answer
446 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(...
1
vote
0answers
12 views

Can I use relational parameters that query as items on their own?

I am running a craft site on craft 2.6.2997 and latest craft commerce. I am building a url query that allows the user to add query params to the url with a bit of js. The url structure is as follows ...
1
vote
1answer
27 views

Pruning the users table

I have a site that deals exclusively with user generated content. After a few years, the users table is getting to a stage where it can probably be pruned of folk who have registered but not actually ...
1
vote
1answer
188 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 ...
0
votes
1answer
215 views

Is it possible to search in Craft Commerce by product type?

I am building an API that takes all products from the Craft Commerce Commerce_ProductModel. In this I am using the Element API plugin to build it out. I am running on Craft 2 latest version. I have ...
0
votes
1answer
51 views

Craft request returns null in test, but works locally

I have a search that is working locally, but not when I push it to my test environment. I imported the database from my local environment into test, so the data should exist. The URL for each is: ...
1
vote
1answer
150 views

Can Craft Commerce products be filtered with multiple query params?

I am using Craft CMS 2.6.2987 and the Craft Commerce plugin. I am building a list of products on a page using query params. The idea is that there are 2 approaches. 1) A user clicks a set of ...
2
votes
1answer
93 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 ...
1
vote
1answer
252 views

RelatedTo query with length criteria

I am trying to get results from a relatedTo query, but only if there are more than say 1 results. Right now I am using two queries to achieve this, like so: {% set authors = craft.entries({ ...
1
vote
1answer
84 views

Query multiple fields with dates

So I'm trying to build a query based on events and their start and end dates. Once a user selects a year, I want to display all events that took place in that year, but also display events that might ...
1
vote
1answer
70 views

craft.matrixBlocks element queries with .type()

I'm using Craft Pro 3.0.0-beta.19 and I try to query matrix blocks with craft.matrixBlocks(). Background: I have event series (=structure) with a matrix block containing 1:n dates for each series. My ...
1
vote
1answer
29 views

Trouble with buildElementQuery customization

I’m having a problem modifying an ElementCriteria with buildElementsQuery. The results elements totally mixes locale results. I can only get english URL for example. Here is a gist of my code. https:/...
3
votes
1answer
41 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 ...
1
vote
1answer
111 views

Search results with partial match to query

I have entry titles that contain dashes (i.e. ABC-123). When I search for 'ABC', 'ABC-123', 'ABC 123', '123' etc the entry is shown in the results (I have fuzzy search enabled). However, when I search ...
4
votes
2answers
123 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
1answer
44 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 ...
1
vote
1answer
69 views

Can anyone tell me what's wrong with the 'andWhere' part of this query?

What am I doing wrong in the 'andWhere' part of this query? I've tried a variety of different ways of doing it but nothing seems to work... It just seems to be ignored. Does anyone know the proper way ...
2
votes
2answers
89 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 ...
1
vote
1answer
141 views

Multiple dropdown filters interfering with each other

I have a multiple dropdown filters that lets users pick the category that they want to display results for below. See my previous question Search entries by location or name for screenshot. So I have ...
3
votes
1answer
193 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 ...
1
vote
0answers
61 views

How to insert data with the querybuilder?

Is it possible to insert data with the query builder if so how? I want to make (backend) fields by queries. What is the easiest way to do this? Or do I have to use regular mysql queries?
0
votes
0answers
65 views

Error while sending QUERY packet on saving entry (user session?)

I have a client that is getting an "Error while sending QUERY packet" message fairly regularly when saving new entries. Specifically, when editing / adding a new entry, he (1) clicks save, (2) Craft ...