Use dynamic content to reference parent looper field

Hello,

I won’t go into all the details of my situation, but I’ve got a looper within a looper where I’d like to compare a string from the parent looper to a string in the child looper for the sake of a conditional element. I was hoping to compare the {{dc:parent:author:display_name}} to the {{dc:child:author:display_name}}. I totally made up those dynamic content references, but I wondered if this kind of thing was even possible.

Hey There,

Thanks for writing in! What you are trying to accomplish may not be possible. Can you please share with us the element structure of your nested Looper? We would also love if we can log in and inspect your page. You can create a secure note in your next reply with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
– Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

image

Best Regards.

So, I’ve got a custom post type created through ACF called “Series.” I created a layout for those “Series” post types, which you can see in action here.

On this layout, as you can see, there is a header, including the title of the series and the author of the series (as chosen on the “Series” post type), I can select this using the dynamic content of {{dc:author:display_name}}. This works as expected.

Underneath, I have a section that contains a row with a looper provider (Dynamic Content => {{dc:acf:post_field field="posts"}}), which loops through an ACF repeater field called “posts”, in which I’ve selected all posts that I want to be a part of this series. This provider is consumed by a column.

Inside of this column, I’ve got another div with a looper provider (Dynamic Content => {{dc:looper:field key="post"}}) that loops through the actual details of the post objects themselves. This provider is set to consume itself.

Inside of this “post” item, I was wanting to create a condition on my author headline element as follows “String: {{dc:author:display_name}} is not {{dc:author :display_name}}.” I want the first DC to be referring to the series author and the second to refer to the post author.

My idea is that if the author of the series is not the same as the author of the post, to hide the author name, because it is redundant.

Does that make sense?

Hello @bobbybosler,

Now I am getting what you have in mind. You can save the author name as an element parameter like as an element parameter of the “Series Post”:

[
  {
    "series_author" : {{dc:author:display_name}}
  }
]

And then you can use {{dc:author:display_name}} IS NOT {{dc:param:series_name}} as your condition to show/hide the author name.

Hope this makes sense.

That makes a lot of sense. I didn’t realize you could use parameters like that. Awesome.

However, upon wiring it all up, it still didn’t work. Even when I created the series_author parameter, when I call it inside the post loop with {{dc:p:series_author}}, it returns the author of the current post and not the author of the series.

Is this a bug or expected behavior?

As proof, see the following page (live here). Note that the "Series: {{dc:p:series_author}}" only shows when logged in.

In the example below, the series_author is “Harold Vaughan”, but the first post returns the wrong author, even though the series_author is referenced outside the loop.

Hello,

I checked out this issue a bit more. The problem being that {{dc:p:series}} value is actually {{dc:author:... which is a context that is changed within the looper. It does really feel like it would be nicer if it built that parameter data in the top level context.

I have a feeling we’ll create a parameter checkbox “Render Top Level” or something like that. I think if we could pass the parent post ID to try to fix this, but there isn’t actually a way to grab the parent post id from dynamic content, unless I missed it. So I will add that feature to Dynamic Content. Unfortunately I think we need a custom filter to fix this on your site. I can take another look at all of this next week as well.

You also don’t need the [] characters in your parameters. I left this alone on your site in case this was on purpose.

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