Questions tagged [queries]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
20 views

Date of latest (parent) related entry?

I have a few sections whose main purpose is to be related to other entries - think authors' names, so a user can click through to all their entries. On the templates for these pages - as well as tag ...
0 votes
1 answer
63 views

What fields are eager loaded by default in Craft Queries?

I'm testing the DB queries required for a Craft query and I realized that adding the title field to the eager loading doesn't change anything. So it seems like the title is retrieved by default. Means:...
0 votes
0 answers
99 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 ...
0 votes
0 answers
126 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 ...
  • 1
0 votes
0 answers
498 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 ...
  • 21
0 votes
1 answer
23 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> &...
  • 69
0 votes
0 answers
189 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, ...
1 vote
1 answer
90 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-...
  • 35
0 votes
1 answer
75 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 ...
  • 1,864
2 votes
1 answer
136 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 ...
  • 1,107
1 vote
1 answer
247 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) { ...
1 vote
1 answer
43 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 ...
  • 218
1 vote
1 answer
66 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 ...
  • 85
1 vote
2 answers
115 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 ...
1 vote
1 answer
671 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 ...
  • 283
1 vote
3 answers
2k 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 ...
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
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.
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
0 answers
35 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 ...
1 vote
1 answer
177 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 ...
  • 80
1 vote
0 answers
70 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
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 ...
0 votes
0 answers
136 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....
1 vote
1 answer
672 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
1 answer
225 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 ...
  • 241
1 vote
1 answer
403 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 ...
  • 495
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 ...
  • 543
3 votes
1 answer
170 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 ...
  • 151
2 votes
1 answer
608 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({ ...
  • 4,696
1 vote
0 answers
161 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 ...
  • 543
2 votes
1 answer
487 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 ...
0 votes
1 answer
450 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 ...
  • 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()->...
2 votes
1 answer
161 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' =&...
  • 143
1 vote
2 answers
101 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 =...
  • 661
4 votes
2 answers
697 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 }...
  • 1,022
1 vote
1 answer
422 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]\...
  • 339
2 votes
1 answer
578 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? ...
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), ...
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 ...
  • 865
0 votes
1 answer
154 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, ...
  • 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....
2 votes
1 answer
772 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 ...
  • 2,957
2 votes
1 answer
316 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 ...
1 vote
0 answers
269 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) ...
  • 539
3 votes
2 answers
921 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 ...
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)
  • 1,293
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 ...
  • 1,293
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 = "...
  • 1,293