Questions tagged [query]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4 votes
3 answers
2k views

Get array of titles instead of whole collection of entries' attributes

I know that to get the entries I can do: craft.entries.all() but instead of getting the whole collection of entries, I would like to get an array of titles from those entries (or any other field). ...
Paloma Martinez's user avatar
4 votes
1 answer
3k 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 ...
Leonardo's user avatar
  • 471
4 votes
1 answer
955 views

Optimizing pagespeed

I'm not sure what is the cause for this page rendering so slow. I thought it was the image transforms but I've removed them and still it's really slow to render. Page in question: http://dharmaavenue....
j00lz's user avatar
  • 769
3 votes
2 answers
5k 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(...
Rosana Ruiz's user avatar
3 votes
2 answers
910 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 ...
peirix's user avatar
  • 431
3 votes
2 answers
1k views

Query entries by custom date field (for a particular year)

So I'm trying to get all entries that have a particular year assigned to a custom date field. (Could be any day/month in that year). The custom field is startDate and my attempt at a query - which ...
James Greig's user avatar
3 votes
1 answer
2k 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 ...
Steven Thate's user avatar
3 votes
1 answer
372 views

How to get column name of an entrie's field

I want to query some entries in a section. I am able to write a query using a GET Param as a filter on the title field. If I want to query a custom field however I need to know the precise column ...
Aram Loosman's user avatar
3 votes
2 answers
2k views

Searching multiple queries using CraftCMS search function

As you can see in the code below I'm currently searching for the keyword but how can I make it so it picks up on entries that have a matching keyword, location & salary or if they don't fill out ...
Adam Ascroft's user avatar
3 votes
1 answer
548 views

How to query entries written in a specific locale? (Craft 3)

In Craft 2 you used to be able to do something like {% set entries = craft.entries.section('something').locale('de') %} but .locale() has been removed and there's nothing similar in the docs that I ...
Ryan's user avatar
  • 1,952
3 votes
1 answer
1k 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! ...
yu xia's user avatar
  • 397
3 votes
1 answer
996 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 ...
Steve Rowland's user avatar
3 votes
1 answer
191 views

Using 'or' within query parameters

I have an entry which shows related events, based on the entry category, at the bottom. These events all have a start date and an end date - the end date is required, if the event is only one day, ...
Grace's user avatar
  • 55
3 votes
1 answer
559 views

'and' & 'or' in the same entry query

I've been attempting to create an entry query that queries the same custom field twice. Basically I want to check if a custom field is between 2 numbers OR if it is empty. Currently I'm using this to ...
Mark Lloyd's user avatar
2 votes
2 answers
1k views

Element query for specific fields

Can a return schema be specified for entry queries? I'd only like the titles instead of the whole entry.
ponies's user avatar
  • 387
2 votes
2 answers
619 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()->...
Jeroen's user avatar
  • 308
2 votes
1 answer
303 views

List Only Available Times/Dates in Solspace Calendar

I have the following code that will output the UNAVAILABLE (previously booked) times of a Target Date. How would i edit this to output (in 30 minute increments) only the AVAILABLE times with Solspace ...
Christopher Healey's user avatar
2 votes
1 answer
35 views

Query entries posted in the past month

I’m trying to show only entries for the created in the last month. I’ve taken this from the example in the docs but it ends up showing nothing. There’s 100% entries with a postDate in the last month. ...
supazu's user avatar
  • 526
2 votes
1 answer
401 views

Excluding specific field value from search

I want to find all entries that match the title field where excludeFromSearch != 1 (is false). {% set query = 'and excludeFromSearch not 1 and ' ~ 'title:"' ~ "myValue" ~ '"' %} {% set results = ...
4midori's user avatar
  • 656
2 votes
2 answers
69 views

Best practice for year based paging

Is there a best practice for a paging based on the years of entries (instead of page numbers)? Example: I have 3 records with post dates 2019-01-01 2018-01-01 and 2016-01-01. So my paging should look ...
Phillip's user avatar
  • 76
2 votes
2 answers
921 views

Get entries after a certain time

I am trying to get all entries from my events section in Craft 3 that occur after 17:00. My current code is: {% set events = craft.entries.section('events').eventStartTime('>= ' ~ '17:00'|time )....
jaypratt's user avatar
  • 113
2 votes
1 answer
116 views

How to structure data: Solo Events (Lectures) and Group of Events (Conferences)

I am working on my first craft project and am wondering how to create the following data structure: I have a page with a large archive of solo-events (lectures, discussions etc). I think I will use a ...
buckdanny's user avatar
  • 187
2 votes
1 answer
284 views

How do you eager load or join reverse relationships for entries?

So I have structures that are related in the follwing way: Locations has many Providers Providers has many Health Topics I know that I can eager load all Locations with related Providers and Health ...
Myles Hyson's user avatar
2 votes
2 answers
124 views

How can I display just the "lowest" categories assigned to an entry and not parent categories?

I have a category tree like this and I have an entry that has four categories A, A1, B, C2: A A1 A2 B B1 B2 C C1 C2 I want a query that ignores A and returns only A1, B, C2, because I don't ...
Travis Smith's user avatar
2 votes
2 answers
844 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 ...
Radmation's user avatar
  • 198
2 votes
1 answer
279 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', '...
Mforeman's user avatar
2 votes
1 answer
179 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. ...
Danielle Frappier's user avatar
2 votes
2 answers
906 views

Getting Unique entries?

I am querying data using the code below. In the database, there are duplicate entries for 'title', how can I get distinct values? $criteria = craft()->elements->getCriteria(ElementType::Entry); ...
user2997606's user avatar
2 votes
1 answer
173 views

How to Check All Users against UserGroup

How can i check if ANY users exist in a particular User Group? I know how to check the current user but not ALL users.
Christopher Healey's user avatar
2 votes
1 answer
664 views

Exclude 2 entries from a query

I know this question has been asked before but I'm still not able to solve the issue in this particular situation. I want to remove one fixed(#95) entry id and the current entry.id from the query. {% ...
Robbie Post's user avatar
2 votes
1 answer
466 views

Multiple relatedTo conditions using a combination of "and" and "or"

We're trying to make a filter that allows you to pick multiple items from 1 category, and multiple items from another category and return back all appropriate elements. We're in PHP land not twig so ...
owenmelbz's user avatar
  • 149
2 votes
1 answer
62 views

Mass enable entries

I'm trying to set statuses to enabled in mysql. Around 150k entries. The tables are elements and elements_sites. Set status to 1. The query runs OK. In the cp is also everything fine but entries don't ...
Mark H.'s user avatar
  • 391
2 votes
1 answer
40 views

Paginate entries ordered by a custom date field

I'm trying to paginate a bunch of events based on their start date. The order part is working correctly, but each consecutive page just loads the exact same entries. My code: {% set events = craft....
Bryce's user avatar
  • 251
2 votes
1 answer
381 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 ...
Danielle Frappier's user avatar
2 votes
1 answer
48 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.
Jeff Irwin's user avatar
2 votes
2 answers
143 views

How 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.
Simon Kuran's user avatar
  • 3,015
2 votes
1 answer
180 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 ...
Romain P.'s user avatar
  • 1,818
2 votes
1 answer
252 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 ...
Eric Chantigny's user avatar
2 votes
1 answer
124 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 ...
Chris's user avatar
  • 143
2 votes
2 answers
166 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 ...
Alan A's user avatar
  • 131
2 votes
1 answer
58 views

Wildcard searching for custom field queries

I've noticed that the * wildcard works for simple custom field queries, for example if I have three entries named Foo, Foo*, Foo*Bar, running craft.entries.title('Foo*').all() will get 3 results, and ...
gioppe's user avatar
  • 414
2 votes
1 answer
21 views

Search Filters Results Unexpectedly

This question is related to: SuperTable Returning Unexpected Results w/ Template, which is still unresolved. In essence, Im trying to return the results of a Supertable at two different points in my ...
Document Services's user avatar
2 votes
1 answer
84 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 ...
emarref's user avatar
  • 123
2 votes
0 answers
362 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 ...
Jorge Anzola's user avatar
2 votes
0 answers
167 views

What's the most performant way to get reverse related entries within an Element Query?

What's the most performant way to get reverse related entries within an Element Query? Here's a contrived example of this. I have thousands of "book" entries and thousands of "collection" entries. I ...
Aaron Bushnell's user avatar
2 votes
0 answers
424 views

How to get url from related entry in another site

I'm relating entries from another site in my installation, and I'm having issues getting the correct URL for the entry. This is an example of what I currently have: {% set carouselEntries = entry....
Vaughn D. Taylor's user avatar
2 votes
0 answers
720 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 ...
Mosswalker's user avatar
2 votes
0 answers
111 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?
Lennard's user avatar
  • 41
1 vote
2 answers
472 views

Offset setting a limit?

If have this in a template: {% for mainLink in section.links.limit(4).all() %} {% endfor %} {% for secondaryLink in section.links.offset(4).all() %} {% endfor %} Which I thought would show the first ...
Tyssen's user avatar
  • 653
1 vote
3 answers
101 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('...
Matthew Rotter's user avatar