Skip to main content
9 votes

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

❗️ This solution will be dramatically simplified in Craft 4.3! Unfortunately, the answer differs pretty dramatically for native properties with "stable" column names and for Content, which (...
August Miller's user avatar
8 votes
Accepted

How do I allow a user to remove an uploaded asset from a front-end entry form?

File fields are used for uploading new images. To delete all the Assets for a field, submit a hidden field with no values. <input type="hidden" name="fields[assetsField]" value="" /> If, on ...
Andris Sevcenko's user avatar
8 votes
Accepted

Entry Form - Multiple Entries & Entry Type & Parent

A little bit late but here it is. Go to https://pluginfactory.io/ and create a plugin, you need at least 1 Controller but you can leave the Name value blank to create a controller with the same Name ...
Robin Schambach's user avatar
7 votes

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

Update for Craft 3.7 Craft 3.7 adds a new field property columnSuffix which is way easier to use than my example code below. Now you can simply access any field's column suffix in Twig like this: {% ...
MoritzLost's user avatar
  • 11.5k
6 votes

How to modify and save a field in entry on EVENT_AFTER_SAVE in a plugin?

The accepted answer works but it's for elements in general, of which an entry is just one. Instead, you can skip checking if the element is an entry (if ($event->element instanceof Entry)) and just ...
Ryan's user avatar
  • 1,952
5 votes
Accepted

Possible to filter an entry based on property?

This should work below. Rather than querying all entries and looping through, just select the entries you need (ie. now) and limit them. {% set upcomingEvents = craft.entries.section('events')....
Siebird's user avatar
  • 373
5 votes

How do I get just the first entry with a 'for' loop?

As you'll only ever be working with one entry I wouldn't bother with the for loop for the first part of your question. Just set a variable with your featured news article. Something like this (not ...
Steve Holland's user avatar
5 votes

Entry next sibling return a deactivated entry

Just an updated version of Marion's answer for Craft CMS 3 since order and first are deprecated. {% set prev = craft.entries.positionedBefore(entry).orderBy('lft desc').one() %} {% set next = craft....
Harald Atteneder's user avatar
5 votes
Accepted

How to filter entries based on Tags

You can combine multiple relationship criteria by passing an array to the relatedTo parameter with the keyword 'and' or 'or' as the first array element. You want your entries to be related to any of ...
carlcs's user avatar
  • 36.3k
5 votes
Accepted

Use global values in the Entry URL Format field

Your CraftCMS global can be accessed using the code {{craft.globals.getSetByHandle('siteDefaults').artworksList.first.uri|default}}/{slug} I believe the issue is that the Entry URL field requires ...
Regan Lawton's user avatar
5 votes
Accepted

How to use category in auto generated title?

In the Title Format field, try: {categoryFieldHandle[0].title}
Aaron Berkowitz's user avatar
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

Send entry as HTML email

You would need to attach such functionality to EVENT_AFTER_SAVE event in the custom php module. The module can be built using plugin factory website. For attaching functionality to the event, you don'...
Piotr Pogorzelski's user avatar
5 votes

Send email notification to admins when a new entry is created

You can do this with a simple module. You can set one up at pluginfactory.io with no controllers and a service called Email. If you're unsure about how modules work or how to set one up, I can highly ...
Martin Spain's user avatar
  • 1,529
4 votes

Create new entry from related Entry field

Not sure when this was added, but this is now available in Craft core. The select modal has a button to create a new entry of that type.
Marion Newlevant's user avatar
4 votes

Change entry status on front end

You need to include a hidden field with the value of 0 before the checkbox to ensure that the value is included in the form data if the checkbox is unchecked. See the docs on templating for checkbox ...
Steve Rowling's user avatar
4 votes
Accepted

Updating an entry record programatically?

After you call $criteria->first(), you no longer have an ElementCriteriaModel, but an actual EntryModel, so probably more semantic to change to: $criteria = craft()->elements->getCriteria(...
Brad Bell's user avatar
  • 67.5k
4 votes
Accepted

Editing entry in front-end

I managed to find a solution, using hidden input fields :) Thank you for all the help :) Edit: Ended up solving this by using tables and saving the username and ID in that. Used a plugin called Super ...
Filip Iversen's user avatar
4 votes
Accepted

Front End Asset Management - Upload New Photos without Deleting/Overriding Existing

You're right that your template needs some adjustments. Whenever you're saving an Assets field, you need to have all of the Asset id's not just the new ones. You're looking for something like {% if ...
Andris Sevcenko's user avatar
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

How to save a new entry with custom fields - Craft 3

It turns out the data wasn't being saved as I hadn't set a fieldLayoutId value. Now that I've figured this out, I've written a helper method to make saving any entry type much easier: public static ...
SteveEdson's user avatar
4 votes
Accepted

Title field character length

You can create a custom validation at the EVENT_BEFORE_SAVE event Event::on(Entry::class, Entry::EVENT_BEFORE_SAVE, function(ModelEvent $event){ /** @var Entry $entry */ $...
Robin Schambach's user avatar
4 votes
Accepted

How to modify and save a field in entry on EVENT_AFTER_SAVE in a plugin?

Following @lenka suggestion, I was able to make the script work this way: use craft\services\Elements; use craft\events\ElementEvent; use craft\elements\Entry; Event::on( Elements::class, ...
Masiorama's user avatar
  • 205
4 votes
Accepted

Exclude most recent entry type from a loop

Best practice is to only query for the data once, then perform any necessary filtering on the result, rather than making multiple expensive calls to craft.entries... So in your case you could take ...
James Smith's user avatar
  • 5,344
4 votes

How to create a new Entry model in Craft 3?

Just so there's an answer here. OP was using Craft 2 code in a Craft 3 environment. The code should be something like this in Craft 3: $entry = new Entry(); $entry->sectionId = $yourSectionId; $...
billythekid's user avatar
4 votes

How to change the name of an entry?

Settings > Sections > [Open your Page] > Change Name > Save
JMKelley's user avatar
  • 1,416
3 votes
Accepted

Redirecting "if entry is not defined" returns 404 instead

The reason you're getting a 404 is because Craft isn't even hitting your help/_entry.html template. Because there's no entry matching the URI /help/asdf, the template will never render and the request ...
Mats Mikkel Rummelhoff's user avatar
3 votes

Editing entry in front-end

Looks like you want to implement a feature to vote for entries. Have a look at these plugins, they make this really easy for you. https://www.doublesecretagency.com/plugins/upvote https://github.com/...
carlcs's user avatar
  • 36.3k
3 votes
Accepted

How to layout a tabbed div

You could achieve this by using a Matrix field for complex content or the awesome Super Table field for something a little more basic Depending on how complicated the content is you are putting in ...
Fyrebase's user avatar
  • 735
3 votes
Accepted

Can't rename slug

You can connect to your database and run: SELECT * FROM craft_elements_i18n WHERE slug = 'forms'; to see what other element is already using the slug forms. To see what type of element it is (Entry,...
Brad Bell's user avatar
  • 67.5k

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