2022 Developer Survey is open! Take survey.

Questions tagged [queries]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
23 views

How to query relations within Supertable field via GraphQL

I have two Entry types: Albums and Songs. On the Albums entry type, I have a SuperTable field (called tracklist) where you can add tracks and select one Song entry per row. On the song page, I'd like ...
user avatar
0 votes
0 answers
11 views

DB Query from specific section

I have a website running on craft 2 and I am having trouble with creating queries in a custom plugin controller. I have a section "tasks" and custom field "ordernr". From the ...
user avatar
  • 1
0 votes
0 answers
31 views

Maximum Response Size in GraphQL API?

hoping someone can point me in the right direction here. I'm trying to query my client's API with the Graphiql interface. My use case requires me to extract quite a lot of data from their system but ...
user avatar
  • 21
0 votes
1 answer
17 views

Multiple entries urls performance

I was wondering if there is a more efficient way, performance side, to call multiple urls for a navigation element in case of a multi language site (so static links are not an option). <div> &...
user avatar
  • 49
0 votes
0 answers
101 views

Duplicate database queries and timeouts

I'm looking to get some advice on excessively duplicated database queries when selecting single types in Craft CMS Our craft instance keeps timing out when trying to load the home page single entry, ...
user avatar
1 vote
1 answer
48 views

Is there a query field?

In Craft, is there a field that allows the user to create a custom query in the back-end? Something similar to the filters in Wordpress' query loop block? https://wordpress.org/support/article/query-...
user avatar
  • 35
0 votes
1 answer
66 views

Improve performance and element queries when used multiple times

So I am building a mega menu and a separate set of templates for mobile. Both use the same set of element queries, which query two larger sections for pages and hierarchy. I am seeing quite slow load ...
user avatar
  • 1,824
1 vote
1 answer
37 views

Craft Event Date Range in Craft

I'm creating a date range where I only want to show upcoming events in the next 30 days based on a start date. I have created my query but when I add my if statement to filter on the start date it ...
user avatar
  • 1,097
1 vote
1 answer
131 views

GraphQL: get prev / next entry from current entry (channel)

Is there a way to get the prev and next entry from the current entry, when this entry is inside a channel and not a structure? query ($id: [QueryArgument], $rel: Int) { entry: entry(id: $id) { ...
user avatar
1 vote
1 answer
39 views

Is this a basic error, or do I misunderstand how Craft queries the database?

I’ve been wrestling with a site from another developer (who will not be named). He seems to have a pretty solid grasp of PHP, and I had assumed that he also understood Craft well. However, as I ...
user avatar
  • 176
1 vote
1 answer
55 views

Help with an Entries field to an array I can use elsewhere

I have an Entries field so I can select a number of posts to feature in a "Hero" section on the home page, as well as a "most popular" section underneath it. However, the Hero ...
user avatar
  • 85
1 vote
2 answers
91 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 ...
user avatar
1 vote
1 answer
426 views

How to search a matrix block with a specific handle?

I want to query a specific matrix block using text search which will search all the searchable fields in that particular block and give me output in the form of blocks that I can further process. I ...
user avatar
  • 283
1 vote
3 answers
1k views

Show Entries based on content in a Matrix Field

I have a product with a variant matrix field(productVariants). Inside each variant is the option to supply a sale price (salePrice). On the front end, I'm trying to show a product grid of only ...
user avatar
2 votes
0 answers
290 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 ...
user avatar
2 votes
1 answer
45 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.
user avatar
1 vote
2 answers
252 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:...
user avatar
1 vote
0 answers
30 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 ...
user avatar
1 vote
1 answer
160 views

Correctly using eager loading in Plugin development

I'm trying to get some data with eager loading, which results in more queries than before. Is there another way to tune down the number of queries as low as possible? As you can see i only need the ...
user avatar
  • 80
1 vote
0 answers
68 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 ...
user avatar
1 vote
1 answer
62 views

Calendar archives architecture

I created a section on a site that shows a two-month calendar. The calendar has links to entries based on a release date. The release dates are created using a date/time filed. (Dates are different ...
user avatar
0 votes
0 answers
118 views

Best way to improve complex query?

This question is related to a previous question I asked: Sort entries in a category via entry field I have a page that is running the same query from the previous question: {% set businesses = craft....
user avatar
1 vote
1 answer
634 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({ ...
user avatar
1 vote
1 answer
177 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 ...
user avatar
  • 241
1 vote
1 answer
396 views

Sort products by category field value

All of my products have a category field called stateCat. These state categories have a field called stateImportance. This is because some states are more important than others and I want to sort the ...
user avatar
  • 485
1 vote
1 answer
48 views

Query is outputting additional results

I have four select drop downs which let the user filter the results by county, development, price and development status. However, I'm getting results showing in the wrong/multiple categories for ...
user avatar
  • 543
3 votes
1 answer
165 views

Using relatedTo programatically?

I'm trying to extend the ElementCriteriaModel using the guide here: https://blog.tighten.co/craft-cms-building-complex-queries-by-extending-the-elementcriteriamodel However I need to re-implement ...
user avatar
  • 151
2 votes
1 answer
519 views

How can I use a WHERE statement in my template?

I am trying query against URL segments. Where I am hung up is how to pass those arguments to a related field. For example, here is my current query: twig {% set profiles = craft.entries({ ...
user avatar
  • 4,696
1 vote
0 answers
157 views

Query category by price

My client has requested to be able to filter the results page by price via a dropdown, which you can see in the attached screenshot. Basically the results page shows a list of around 15 property ...
user avatar
  • 543
2 votes
1 answer
440 views

Better way to group by category and include full category entry

The basic idea is that I want to group my entries by category, but I want more than just the category title—I need the entire category entry. My previous post alludes to this, but I've since ...
user avatar
0 votes
1 answer
395 views

Anyone have a createCommand example?

So I am using a plugin to import data and it isn't assigning the values (asset is inside of Matrix) so I am going to modify the plugin and add code to lookup values that I need to assign to ...
user avatar
  • 109
4 votes
2 answers
1k views

Query only returning 100 records at a time?

I am trying to export data from a database to a csv file, I am using the code below to retrieve the data from the DB, but it only returns 100 rows, how can I fix that? $criteria = craft()->...
user avatar
2 votes
1 answer
157 views

Is it possible to skip entries with children?

Hi I m using elementapi plugin to create an json object from my elements. I would like to get all entries, but not those ones who have a children. My criteria it looks like this now 'elementType' =&...
user avatar
  • 143
1 vote
2 answers
100 views

Tag mysteriously not found

Weird issue where a tag was not found using the tags search query. That tag is in the CMS (in news entries) as well as the DB, and even shows up in other queries. Query in question: {% set tag =...
user avatar
  • 621
4 votes
2 answers
661 views

When is the find() method actually necessary?

I've noticed code samples like the following that use the find() method. {% for entry in craft.entries.section('blog').limit(5).find() %} <li><a href="{{ entry.url }}">{{ entry.title }...
user avatar
  • 1,022
1 vote
1 answer
418 views

Queries in devMode

When I look at the console log when devMode is enabled, I notice there's a lot going on, and I'm not sure if what I'm seeing is normal or not. There are dozens of [trace][system.db.CDbCommand]\...
user avatar
  • 339
2 votes
1 answer
529 views

How to write query with startdate <= now && enddate >= now?

I'm trying to make a query which has 2 conditions who has to be true both. In PHP I should use && to get this. startdate <= now && enddate >= now. How do I write this in Craft twig? ...
user avatar
0 votes
1 answer
176 views

Freelance work available [duplicate]

I am looking for some support as the developer who built my site (www.lexiconthai.com) is no longer available. I need a few small changes doing right now (adding meta tag plug in, changing fonts), ...
user avatar
0 votes
0 answers
86 views

Advanced search form with checkboxes [duplicate]

So it seems that Matrix fields don't work with the object syntax so I've changed my field structure to use standard dropdowns, checkboxes and a number field. I have the dropdown (gender) and number ...
user avatar
  • 865
0 votes
1 answer
151 views

craft.request.getQuery returns empty on multi lingual site

I have the strangest bug. I have a site with two languages, Norwegian and English. In my code i check for craft.request.getQuery('prodid'). Locally in Apache this works fine with both language URLs, ...
user avatar
  • 268
3 votes
1 answer
1k views

How do I sort a collection of entries from multiple sections by date?

I want to create a featured story slider on my website and gather the latest entries from multiple channels to populate it. Here is what is working: # fetch the entries {% set featuredBlog = craft....
user avatar
2 votes
1 answer
705 views

Using relatedTo, and/or and :empty/:notempty in queries

I got users that has 3 Entries fields in their profile: breadForMonday, breadForWednesday and breadForFriday. I want to differentiate between users with 1, 2 or 3 selected entries. How would I use ...
user avatar
  • 2,947
2 votes
1 answer
315 views

Find Entries with Multiple Matches in a Single Field

I have entries in a channel called "shorts". Each of those entries has a field called "size" that can be a value of small, medium or large. I have created a form where I want users to be able to ...
user avatar
1 vote
0 answers
254 views

Limit fields in query / Optimize query

What I'm doing is fairly simple: {% cache %} {% set jobs = craft.entries.section('job').find({ order: 'dateCreated asc', limit: 0 }) %} {% for job in jobs %} {{ macros.jobProfile(job) ...
user avatar
  • 539
3 votes
2 answers
855 views

Check if Category is in Query

I'm trying to check to see if a particular category (In a loop) exists in a query submitted from a search form. At the moment I'm doing this inside a 'childCategory' loop... {% for childCategory in ...
user avatar
0 votes
1 answer
33 views

How do you find more documentation about queries, services, plugins, etc?

So I've been having so much trouble finding adequate examples of how to do things when writing a plugin. How do you find more? (see below for my own answer)
user avatar
  • 1,263
0 votes
2 answers
2k views

Using Services to get all the Categories related to an Entry?

In a plugin, I've been advised to try to use craft built-in services instead of direct db queries. So can anyone help with this: For an entry type that includes a categories field, how to get all the ...
user avatar
  • 1,263
1 vote
1 answer
2k views

db query to get fields related to entry

Sorry if this question is starting off too abstract. I'm porting a calendar plugin from Textpattern and WordPress into Craft. Basic workflow for the output has been (in twig terms): {% set start = "...
user avatar
  • 1,263
4 votes
1 answer
551 views

RelatedTo Query Using Both "and" and "or"

I'm attempting to build a filter that queries entries of a section based on two criteria: A selection of one or more categories (inclusive), and a single related entry (exclusive). Specifically, the ...
user avatar
  • 419
4 votes
1 answer
759 views

Query to element criteria

Is it possible to turn a query into an element criteria model? Currently I'm doing this: $criteria = craft()->elements->getCriteria('Conference_Session'); $criteria->conferenceId = $...
user avatar
  • 481