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 entries to get the field values.
{% for block in entry.menuLinks %}
{% set relatedEntries = craft.entries.section('SectionName').relatedTo(block) %}
{% for entry in relatedEntries %}
<a href="{{ entry.url }}">{{ entry.title }}</a>
{% endfor %}
{% endfor %}
If you know there is one and only one block or related entry then you can skip the for..in
loop(s) and just use the .first()
method (i.e. entry.menuLinks.first()
and or craft.entries.section('SectionName').relatedTo(block).first()
);
Keep in mind that if you are just trying to create a simple list of links to related entries you do not need a matrix field at all (unless of course you are doing something more complicated). The Entries Field Type itself can support an unlimited number of related entries (and are sortable), so you could just create an entries
field directly in programs
.