13 votes
Accepted

How to output an Entries Field value within a Matrix Field block

You get this error because {{ block.slideLink }} returns an array of EntryModels (even if you set your Entries field up to only allow 1 entry). So you need to add the first() method to get the first (...
user avatar
  • 35.8k
8 votes
Accepted

How do I use a Dropdown 'Entries' Field Type in a Front End Form

Simply put, an Entries field is an array containing entry ids, and your form needs to send it that way. Just replace name="fields[tbdDesignerUrl]" with name="fields[tbdDesignerUrl][]". That way the ...
user avatar
  • 8,316
8 votes
Accepted

How could I have a plugin hook into when I edit or update a post?

Craft has Hooks and Events which get invoked at different points in the core code. In your case the entries.onBeforeSaveEntry event would be perfect. Example: public function init() { parent::...
user avatar
  • 8,316
7 votes
Accepted

How to use a global variable in a conditional statement if an entries relation field is empty?

The reason it wasn't rendering is because my original entry field is an Entries Field (see templating examples in the docs). The relationship fieldtypes (Entries, Assets, Users) require that you ...
user avatar
  • 605
7 votes

How to output an Entries Field value within a Matrix Field block

All related fields (assets, entries, categories, tags, etc) are designed to store more than one item, and thus always return an "array-like" object (although not technically an array), even if you ...
user avatar
6 votes

Programmatically update entry field

I got around this issue by looping through all fields that were of BaseElementFieldType re-setting them to their current value. $fields = $entry->getFieldLayout()->getFields(); $...
user avatar
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 ...
user avatar
  • 2,824
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, ...
user avatar
  • 6,672
5 votes
Accepted

Get related entries from matrix field

Related entries in a matrix field are technically related to the matrix block and not the entry. So you will first want to get the related entries via relatedTo(block); then loop through the related ...
user avatar
5 votes
Accepted

Is it possible to limit the level at which entries can be selected from within an entries field?

There's already a popular feature request for this: "Entry Type" setting for Entries fields But yes, it's currently also possible to do this by extending the default entries field type and adding ...
user avatar
  • 35.8k
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 ...
user avatar
  • 7,238
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" ...
user avatar
  • 66.4k
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....
user avatar
  • 35.8k
5 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 ...
user avatar
  • 3,924
4 votes

Checking if a matrix field with entries has more than one entry

I believe the code below should work. This code assumes you are on a single entry page or within a loop and your entry is available to you with the entry variable. You may need to adjust the block....
user avatar
  • 13.2k
4 votes
Accepted

What's the best way to paginate through entries from an entries field type?

To do this, you would need to use getPrev() and getNext() on the related entries’ template. The trick is telling getPrev() and getNext() to use the order you defined in the source entry’s Entries ...
user avatar
4 votes
Accepted

Hide (or disable) an entry field in CP depending on user group permission?

OK so here is my solution : 1/ define a custom permission for user groups public function registerUserPermissions() { return array( 'updateTopNews' => array('label' => Craft::t('...
user avatar
  • 972
4 votes
Accepted

Outputting Matrix blocks with grouped values based on Entries field id

Try something like: {% set breadGroups = entry.breads | group('bread.first.id') %} {% for breadId, blocks in breadGroups %} {% set sum = 0 %} {% for block in blocks %} {% set sum =...
user avatar
  • 3,400
4 votes

Programmatically update entry field

You're very close. Try this: $entry->getContent()->setAttribute('metaStatus', 'Declined'); craft()->entries->saveEntry($entry);
user avatar
  • 7,238
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 ...
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=...
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}
user avatar
3 votes
Accepted

How to use a dynamically defined field handle in a plugin?

This should do it for you: $entry->$fieldHandle->last()->uri;
user avatar
  • 66.4k
3 votes
Accepted

If loop contains id `X`

{% if '4' not in navigation.navi.ids() %} {% exit 404 %} {% endif %}
user avatar
3 votes

Order "Entries Fields" by entry order

It's order('sortOrder') instead of fixedOrder(true). {% set entries = craft.entries({ relatedTo: { sourceElement: entry, field: 'entriesFieldHandle' }, order: 'sortOrder', limit: null }) %...
user avatar
  • 35.8k
3 votes
Accepted

Get matrix entries related to an image asset via specific field

While you said that Attempt 1 was giving you the correct entries, just in the wrong order, if you have two blocks, you will probably find that you’re getting all blocks’ related entries each time. ...
user avatar
3 votes
Accepted

Add, remove, and append entries to an entries field via frontend form

You guessed right, you have to set all already added entries again. To do this, just have some Twig logic when outputting the fields: {% for currentTeam in entry.tournamentTeams %} <input type=...
user avatar
  • 35.8k
3 votes

Programmatically update entry field

I'm not completely sure of the technical reasons (I guess something to do with relation fields not have a column in the craft_content table), but you also need to re-save the existing ids for any ...
user avatar
  • 4,361
3 votes
Accepted

How can I merge entry values to create a select dropdown

You are using a dropdown field, so you can't query for the counties in use directly from the database. (This would be possible if you had chosen to use categories or tags for them.) But what you can ...
user avatar
  • 35.8k
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 ...
user avatar
  • 23.6k

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