6 votes
Accepted

Many db requests with relationship fields

This is how relationships work in Craft at the moment. Each relation equals +1 query. If you don't access your relation on an entry the query isn't executed. So by only fetching title and/or id you ...
naboovalley's user avatar
  • 2,844
6 votes
Accepted

Set Entries field in Commerce order on completion

See What is getContent() / the ContentModel, and how do I use it to get and set custom field values? So you needed to change the method used for setting content on an element. Also see In a plugin, ...
Luke Holder's user avatar
  • 6,827
6 votes
Accepted

How to find next sibling from entry order of parent entries field

nextSiblingOf() and related methods will only work with Structure entries. What you need instead is next() / prev(): https://docs.craftcms.com/api/v3/craft-base-element.html#next (At the time of ...
James Smith's user avatar
  • 5,189
5 votes
Accepted

Exclude "featured" entries from a "recent" entries {% for %} loop

What you could do is get the ids of the featured element, and exclude those from the second craft.entries call. Something like this: {# Get the ids of the featured items you got above #} {% set ...
André Elvan's user avatar
  • 7,288
5 votes
Accepted

How to create an entry

From your screenshot, it looks like you've added a Single section, which by definition, there will only be one "entry" in. Since there aren't any other types of sections, you don't have a "New Entry" ...
Brad Bell's user avatar
  • 67.5k
5 votes
Accepted

Sorting Entries field results by category

It’s not totally clear from your question where you’re building the relation to the categories, but I have a feeling that this is the solution you’re looking for. {% set groupParam = '{ object....
carlcs's user avatar
  • 36.2k
5 votes
Accepted

How to get column name of an entrie's field

It's actually OK to hard code the complete field column name (i.e. field_nationality_gkpaccfs) – it won't change between environments, or if the field is resaved (unless you change the handle, of ...
Mats Mikkel Rummelhoff's user avatar
4 votes

How do I set the value of a custom entries order field from a plugin?

I was close. I was correct in assuming my syntax was incorrect for setting the value of an entries field. Since an entries field is an array of elements, not just a single element, I just needed to ...
jthomas's user avatar
  • 373
4 votes
Accepted

Frontend form with relation to an entry

After research with lots of trail & error I found the solution. I just had to add [] to my hidden field to establish the relation: <input type="hidden" name="fields[assetId][]" value="1478" id=...
Marco's user avatar
  • 213
4 votes
Accepted

Setting channel url format to include value of entries fieldtype URL

It needs to be: {destination.first().slug} Or if this is for Craft 3: {destination.one().slug}
Brandon Kelly's user avatar
4 votes
Accepted

On a Craft 3 multi-site, how can I setup an Entries field to select entries from other sites?

In entries field has an option Show the site menu, so this will give you a dropdown to select site when selecting entries. But the problem it doesn't save the site relation. If your channels is only ...
aodihis's user avatar
  • 801
4 votes
Accepted

Parent based Selectable Entries Condition

Rendering Twig in the "Selectable Entries Condition" field setting isn't actually possible, but it will be in the upcoming Craft 4.4 release, which as of writing this (march 1st 2023) is due ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Why if I change ie. drop down value, all entries needs to be resaved to take changes? How can I prevent it?

Dropdown fields (and other simple option-based fieldtypes such as Radio Buttons, Checkboxes and Multi Select) are pretty dumb. By design, whenever an Entry with a Dropdown field is saved, Craft ...
Mats Mikkel Rummelhoff's user avatar
3 votes

Accessing custom fields from User Model

Response via Slack from Brandon Kelly: Accessing custom field values from PHP is the same as in Twig - once you have the UserModel it's just $user->myCustomFieldHandle or $user->...
Cole Henley's user avatar
  • 1,741
3 votes

Programmatically update entry field

Craft 3 $entry->setFieldValue('my_field_handle', 'new_value'); $app->elements->saveElement($entry);
Simon Epskamp's user avatar
3 votes
Accepted

The smoothest way to store JSON object to an entry?

It's a little tough to say, since you it seems like you haven't actually architected any of this in the Craft back-end yet. I encourage you to create a field (or fields) which would be a good ...
Lindsey D's user avatar
  • 24k
3 votes
Accepted

Related Entries not sorting correctly

When you include templates and pass multiple different variables to them with different types that may have a different field layout it is required to code defensively and check for variable types. ...
Robin Schambach's user avatar
3 votes
Accepted

Use an entry field's value in body class

You've assigned the string 'work modifierClass' to the bodyClass variable, rather than adding the value of the modifierClass variable to bodyClass. You can assign the value of modifierClass to ...
Martin Spain's user avatar
  • 1,519
3 votes
Accepted

Output specific entry from entries field based on position

{% set allEntries = entry.entriesSelector.all() %} <ul> <li>First: {{ allEntries[0].title }}</li> <li>Second: {{ allEntries[1].title }}</li> <li>Fourth:...
James Smith's user avatar
  • 5,189
3 votes
Accepted

Eager-load entry field that is being paginated

When relational fields (entries, assets, etc) are eager-loaded, they either return an array of elements (Craft 3) or a Collection (Craft 4). Neither of those are possible to paginate using the {% ...
Mats Mikkel Rummelhoff's user avatar
2 votes

How to get all (prepped) field values from an entry, indexed by field handle

I kept thinking this was in the Craft core. Wasn't, so I made my own: https://gist.github.com/timkelty/933efd23264d79d91b7a Has come in useful in plugin dev and some templating.
Tim Kelty's user avatar
  • 3,081
2 votes
Accepted

Relating entries to assets within an ElementAction

So it seems what I was doing wrong was passing in a single $artistId rather than an array. With the change shown below it works as expected: foreach ($assets as $asset) { $artistFieldModel = ...
Emyr Thomas's user avatar
2 votes

Exclude "featured" entries from a "recent" entries {% for %} loop

{# set featured entries by finding their IDs #} {% set featuredEntries = entry.featuredArticles.ids() %} {# set all entries by finding their IDs #} {% set allEntries = craft.entries.section('blog'...
John Johnson's user avatar
2 votes

Put simple content into Craft and grab it in JavaScript

One way to go about this is to use the JSON Expand plugin from Familiar Studio: https://github.com/familiar-studio/craft-json-expand It's pretty easy to use: {% set hpContent = craft.entries....
Ryan's user avatar
  • 1,952
2 votes
Accepted

Showing related entries field

So your Case Study has a field called services which is an entry relation. You show the services on that Case Study page using // entry is the current Case Study {% set related_services = craft....
Luke Pearce's user avatar
  • 3,863
2 votes
Accepted

Restricting relationship field by author

Brad is correct – this isn't possible to do without writing a plugin. For your particular use case, this will be very simple, though. What you'll have to do, is to write a custom FieldType that ...
Mats Mikkel Rummelhoff's user avatar
2 votes

Restricting relationship field by author

Craft's permission system doesn't go down to the field level, which is what you're looking for. You'd either have to replicate the functionality you're looking for on the front-end of the site, or ...
Brad Bell's user avatar
  • 67.5k
2 votes

Matrix with an entries field and need to grab category title

To achieve structure: Country Name A Reseller C Country Name C Reseller B Reseller D With configuration: Category Countries Channel Resellers: rdCountry (Country Categories) field Channel ...
Krzysztof Boduch's user avatar
2 votes
Accepted

Passing Multiple Relation Criteria In Plugin

I need someone more experienced with Craft to vet this, but it seems that this is working: Supplying an array to relatedTo returns results if it matches one OR the other entry. $projectCriterea = ...
JamesNZ's user avatar
  • 937
2 votes
Accepted

Sort entries in a category or entries field?

To order the products you'd make the Products section into a structure and display the category you were sorting by in the listing as a table column. You can then re-order all products to be in ...
Luke Pearce's user avatar
  • 3,863

Only top scored, non community-wiki answers of a minimum length are eligible