<If loop exists...> breaks post loop

Hi there,

I had a post loop that was working fine, but when I tried to add an If statement to check if posts exist, it broke everything. Perhaps this is because I have nested If statements, is that even allowed?

I followed the documentation here:
https://docs.loopsandlogic.com/104/how-to-show-posts-only-if-they-exist-and-display-a-message-if-they-dont-exist

Here is the template (It’s a little complicated):

code removed

Thanks.

Hey Phil, I’m noticing that the letter L in your tag is lowercase, whereas all of L&L’s dynamic tags are supposed to be written with uppercase letters, like <Loop>. Does fixing both instances of that solve your problem?

Thanks, that seemed to fix it, but I knew about that issue so I’m not sure how I missed it.

@benjamin could you please advise on a related matter…

I am using the author="current" parameter to return posts for the currently logged-in user, but it only seems to work if the user is a WP administrator. If I change the user role to Editor or anything else, the user’s posts are not returned. Is this a limitation of the author tag?

Example code:

<If loop exists type="post" orderby="date" order="desc" author="current">
    <Loop>
        <Field title />
        <a href="{Field edit_url}">Edit post</a>
    </Loop>
    <Else />
    <p>There are no posts!</p>
</If>

Thanks.

I just tested this out with your exact template on a test site of mine and it worked as expected; I had a user with an editor role who had authored some posts and when I signed in as that user, I was able to see a list of the posts that user had authored.

Out of curiosity, what happens when your template doesn’t work? Does nothing appear, or does your “There are no posts!” message appear? If it’s the latter, then are you sure that the editor user has posts on which they’re listed as the author?

I’m not sure I’ll be able to troubleshoot more without being able to replicate the issue, but maybe try breaking down your template into pieces and try to identify which part of the process seems to be not working in your case.

After trying many other things, this was resolved by simply resaving the Elementor page which contained the template :man_shrugging:

1 Like