<p>You can run a related to query, passing in all of the descendants of the 'parent' structure entry like so (assuming you are on the 'parent' entry page, else you'll need to query that entry first)</p>

<pre><code>// Get the index pages children 
{% set descendants = entry.descendants.all() %}

{% set recentBlogPosts = craft.entries({
  section: blog,
  relatedTo: descendants,
  limit: 3,
  orderBy: 'postDate desc'
}).all() %}

</code></pre>

<p>Or, if you don't mind getting blog posts related to the parent page also, you can use the fact that in order to be related to a child page, a blog post must also be related to the parent:</p>

<pre><code>{% set recentBlogPosts = craft.entries({
  section: blog,
  relatedTo: entry,
  limit: 3,
  orderBy: 'postDate desc'
}).all() %}
</code></pre>

CC BY-SA 4.0
2019-08-19T18:51:07.413Z
Thank you very much. This solved my challenge!
Jon Smith
CC BY-SA 4.0
2019-08-19T16:10:22.397Z
2019-08-19T16:10:22.397Z
Nick
<p>fairly new to craftCMS. I've wrestled with this now for hours and exhausted all research avenues. </p>

<p>I have three main "service pages" (Web Design, Digital Marketing, Hosting &amp; Analytics) These are top level Structure pages, each with 5 entries - for example Web Design/Web Development, Web Design/User Experience, Digital Marketing/Inbound, Digital Marketing/SEO, etc. etc. </p>

<p>I have set up an 'entries'field type called 'blogServices' that uses the three main service pages as the parent source, and allows me to select the child pages with no issue. So for instance, if I write a post about Web Development, I can select the 'Web Design/Web Development entry with no problem and have it show up as a related service on the blog post. </p>

<p>Where I am running into a roadblock is I want to pull up 3 most recent blog posts on my 'Web Design' index page. However, I want to be sure that the three most recent posts fall under one of the five 'Web Design' child service entries (side note: Each blog post can also fall under multiple services as well).</p>

<p>Any help with showing me how to filter out only these posts on the index page is of course greatly appreciated. I've been trying the 'relatedTo()' function with no luck at all.   </p>

<p>Thank you in advance.</p>

<entry><structure><fieldtypes><relatedto>
Pulling blog entries related to a structure entry field type
# Pulling blog entries related to a structure entry field type

(Asked by: username_0 on 2019-08-19)

fairly new to craftCMS. I've wrestled with this now for hours and exhausted all research avenues.

I have three main "service pages" (Web Design, Digital Marketing, Hosting & Analytics) These are top level Structure pages, each with 5 entries - for example Web Design/Web Development, Web Design/User Experience, Digital Marketing/Inbound, Digital Marketing/SEO, etc. etc.

I have set up an 'entries'field type called 'blogServices' that uses the three main service pages as the parent source, and allows me to select the child pages with no issue. So for instance, if I write a post about Web Development, I can select the 'Web Design/Web Development entry with no problem and have it show up as a related service on the blog post.

Where I am running into a roadblock is I want to pull up 3 most recent blog posts on my 'Web Design' index page. However, I want to be sure that the three most recent posts fall under one of the five 'Web Design' child service entries (side note: Each blog post can also fall under multiple services as well).

Any help with showing me how to filter out only these posts on the index page is of course greatly appreciated. I've been trying the 'relatedTo()' function with no luck at all.

Thank you in advance.

**Tags:** entry, structure, fieldtypes, relatedto


---

## 1 answers

### Answer by username_1 on 2019-08-19. Score: 1 | Accepted answer

You can run a related to query, passing in all of the descendants of the 'parent' structure entry like so (assuming you are on the 'parent' entry page, else you'll need to query that entry first)
// Get the index pages children 
{% set descendants = entry.descendants.all() %}

{% set recentBlogPosts = craft.entries({
  section: blog,
  relatedTo: descendants,
  limit: 3,
  orderBy: 'postDate desc'
}).all() %}


Or, if you don't mind getting blog posts related to the parent page also, you can use the fact that in order to be related to a child page, a blog post must also be related to the parent:
{% set recentBlogPosts = craft.entries({
  section: blog,
  relatedTo: entry,
  limit: 3,
  orderBy: 'postDate desc'
}).all() %}

> **Comments:**
> **username_0**: Thank you very much. This solved my challenge!  

---

