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

Questions tagged [query]

The tag has no usage guidance.

1
vote
2answers
14 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 ...
1
vote
1answer
10 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
15 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
11 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
50 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
26 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
37 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
42 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
16 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
39 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
33 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
27 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
91 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
28 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
22 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
17 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
32 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
26 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
56 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
75 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
185 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
60 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
125 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
38 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
46 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
37 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
72 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
89 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 ...
3
votes
1answer
333 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
478 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
152 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
70 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
73 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
81 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
123 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
39 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
689 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
15 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
30 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
282 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
329 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
56 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
199 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
115 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
326 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
100 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
72 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
32 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
50 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 ...