Questions tagged [queries]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
3answers
64 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 ...
1
vote
0answers
45 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 ...
0
votes
0answers
27 views

How to query Elements with an entry field count of zero

I have an Entry 'Product' which cans zero or more 'Components' I am trying to figure out how to query all Product entries that have zero components. I can do this to get everything: $entries = ...
2
votes
1answer
22 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
2answers
133 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
0answers
21 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
1answer
55 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 ...
1
vote
0answers
47 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
49 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
0answers
90 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
1answer
422 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
128 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
283 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 ...
1
vote
1answer
44 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 ...
3
votes
1answer
149 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 ...
2
votes
1answer
97 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({ ...
1
vote
0answers
109 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 ...
2
votes
1answer
191 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
1answer
217 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 ...
4
votes
2answers
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
1answer
145 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' =&...
1
vote
2answers
88 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 =...
4
votes
2answers
404 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
vote
1answer
362 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]\...
2
votes
1answer
183 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
1answer
154 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
0answers
81 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 ...
0
votes
1answer
129 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, ...
3
votes
1answer
940 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
1answer
379 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
votes
1answer
252 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
0answers
190 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) ...
2
votes
1answer
517 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
1answer
30 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)
0
votes
2answers
1k 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
vote
1answer
1k 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 = "...
3
votes
1answer
355 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 ...
4
votes
1answer
705 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 = $...
1
vote
1answer
154 views

Prevent queries based on condition

I have a set of parameters that need to be checked before outputting an entry in a particular section of a website. The code for that looks somewhat like this: {% for slide in craft.entries.section('...
3
votes
2answers
2k views

How to query using variables

I'm having issues with getting results from a query. I have 2 search parameters which i have set to variables. I would like to match both of these to get results. At the moment the query is returning ...
2
votes
1answer
2k views

How to get query or param from URL and then use in Links?

I'm trying to grab the query or param from an URL and then add it to an URL. like products?price=15 How can I add the ?price=15 to a URL? Like products/category?price=15?
13
votes
1answer
3k views

Is it possible to exclude multiple sections from an entry search query?

I'm trying to build a search function that excludes results from certain sections all together. This is the code I was trying to use. {% set entries = craft.entries.search(query).section('not ...
1
vote
1answer
422 views

Finding entry by content

I'm currently creating a plugin for craft and have stumbled across a slight problem. I'll try summarise of what I am doing and what I am trying to achieve. So, I'm trying creating a plugin which will ...
1
vote
1answer
494 views

Using modifyElementsQuery to get plugin's custom table data

I need to join my plugin's custom table to a an ElementCriteriaModel (ECM). I am trying to use modifyElementsQuery. In the plugin's custom table, rows can share an element/entry via a separate id. ...
0
votes
0answers
207 views

Complex queries

I'm wondering: what is the best way to do complex queries for a plugin? For example, I'm building a site that publishes stories and sometimes the same story can be in different languages. The ...
7
votes
1answer
1k views

How can I do more complicated queries with an ElementCriteriaModel?

I need to join my 3rd party table with a standard ElementCriteriaModel (ECM). I'd like to start with an ordinary ECM, so my plugin will be compatible with any element type which may exist, now or in ...
4
votes
2answers
442 views

What's the difference between ElementCriteriaModel and DbCommand?

Forgive me if this is a stupid or naive question... I generally think of an ElementCriteriaModel as being a "search object". Specifically, it's a search object which revolves around a specific type ...
5
votes
1answer
742 views

How can I expand on a normal Craft query to sort by a column in a custom table?

I have a plugin which contains a Record. My record contains a foreign key of the related element ID. The only other column in my custom table is the value I'd like to sort by. In Twig syntax, how can ...
5
votes
1answer
550 views

How can I reduce the number of queries when including a related item within a for loop

I've created an alphabetical index of entries in my template. The code I'm using is in the gist below: https://gist.github.com/jamiepittock/2635516e95317e5c6ed6 It results in a layout like the one ...
3
votes
1answer
594 views

Get entries by date but ignore time

I'm trying to pull entries from a database where the postDate is a specific date. {% set today = thisyear ~ "-" ~ thismonth ~ "-" ~ day %} {% set today = today|date('Y-m-d') %} {% set entries = ...