Nesting loopers

Hello @ruenel , seeing as you understand Loopers very well, I thought I’d ask you about something, instead of spending several hours trying to figure it out…

I have a Post Type for Frequently Asked Questions. Each post within this type has two custom fields: “Answer” and “Subject (which could be linked to a custom taxonomy, if it helped)”. The “Question” would be the title of the post. My client will add new posts (Questions), and might add new “subjects”.

I want to create a page that will automatically populate with all the data, and update whenever a new question or subject is added, using the following structure:

 Subject 1

 Q1
 A1

 Q2
 A2
 ...

.

Subject 2

    Q1
    A1

    Q2
    A2
    ...

My guess is Nesting loopers, first pulling the “Subject” and outputing it in a Headline element, and then pulling the individual questions, but filtering by the aforementioned “Subject” and outputing them and their answers in Headlines and Sub-headlines.

However, I have no idea how to achieve this. What would be the best way to do this? Thanks!

Hi Oriol,

Thanks for reaching out.
It seems that you are trying to show the FAQ posts based on the subject i.e. taxonomy and where the Question will be the title of the Post.
I have tried in my local environment with the category and the posts and achieved what you are trying to do. I would suggest you follow the below steps which I have done.

Category based Posts

  1. Implement the All Terms type and select the specific Category of Looper Provider to the Column named Category Loop.

test-new-Content-Pro - 2021-05-27T151249.406

  1. Added a div with a ID with term{{dc:term:id}}

  2. Added the Text element to show the Category Title i.e. Subject in your case using {{dc:term:name}}

  1. Added a div element and implemented the nested loop of Query String with the following Query

    category_name={{dc:term:name}}&post_type=post&posts_per_page=3&offset=0&ignore_sticky_posts=1

test-new-Content-Pro - 2021-05-27T151716.195

NOTE: You need to change the Query String based on your post type and taxonomy.

subject={{dc:term:name}}&post_type=faq&posts_per_page=-1&offset=0&ignore_sticky_posts=1

  1. Added a Headline element to show the Post Title inside the Div element.

  1. You need to add a Text or Headline element to show the answer from the custom field using the {{dc:post:meta key=“answer”}}

I would also suggest you go through the following documentation and videos on Looper


Hope it helps.
Thanks

Thanks for the Reply! In the end What I did was make the Post type the “Subject”, and I created a repeater Custom Field for the “Questions”, which in turn has 3 fields: “Question”, “Answer”, and “More Info Link”.
Following this video: Loopers: Nesting Repeaters with ACF Pro.
I’m pulling the Questions using {{dc:acf:post_field field=“questions”}} and it works fine, I’m able to consume “Question”, “Answer”, and “More Info Link”. My question now is, is there a way to add an expression to sort the items (“Questions”) alphabetically by “Question” (like the Query Builder dropdown)?

I was thinking something like {{dc:acf:post_field field=“questions”,‘orderby’ => ‘question’,‘order’ => ‘ASC’}} but I’ve had no luck.

Hi Oriol,

Regretfully, there is no such option available within the Dynamic Content for the ACF fields.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.