Using Looper Queries

Hey all!

I want to use a looper to show only specific posts that a user is allowed to see. I’d like to assign this access each time I make a post, so I have a couple options:


Option 1) Use an author/co-author/guest-author approach and simply add the user as an author. I imagine the code would look like this:

category_id=25&author={{dc:author:id}}

The problem I have with this method is that using a plugin like CO-AUTHORS PLUS or PUBLISHPRESS AUTHORS modifies a post’s author meta from a string into an array (I’m pretty sure anyways, didn’t actually check) which appears to cause reliability/compatibility problems using the above string for the looper provider.


Option 2) Use an ACF relational field (at the post, or possibly user level) to control what post gets attributed to which user. I’d like to test this option out rather than troubleshoot the other one… however, I’m unsure what the best approach might be in the looper provider settings. Consider that I need:

  • Only show posts from 1 specific category, and
  • Only show posts in that category that have been given a relationship (ACF) to the logged-in user, specifically.

What’s the best practice for achieving Option 2 above?

Also… which option sounds better in your opinion, or is there another way to achieve this that I’m not seeing (optional response to this question; here for curiosity’s and verification’s sake).

Hi @Rule72,

Thanks for reaching out.
The Option 1 is better to use, but if you are really sure that another plugin is affecting the meta values you can’t use this option. And in that case, you can use the Option 2 by establishing the relationship using the ACF and use the Query String with the ACF fields.

Hope it helps.
Thanks

Thanks for your feedback!

I do agree that Option 1 is much better for this approach to UAC (considering that I can make a post “private”, and only authors can then view it, rather than anyone with the URL unless I utilize other controls).

However, I’m still having problems determining the source of my issue. When I have only a single author on the stock WP install, the query string above works just fine; however, when I use a plugin to add multiple authors, the query does not work.

Note that Option 1 actually HAD worked until somewhat recently (using the plugin Co-Authors Plus but not PublishPress’ version), although it had intermittent issues until it stopped altogether around 2 months ago.

I suspect that it’s like I said above (that a multi-author plugin breaks other plugins’ author query functions), but at this point can I have your team confirm?

Worst case, I’ll use ACF and another plugin (such as Restrict Content) to take care of direct-link accessing.

Hello @Rule72,

With this query string author={{dc:author:id}}, it will work in displaying posts from a specific author. Since the 3rd party plugin modified the authors of the post, you will need to come up with a different query string. You will need to identify what is the custom field for the Co-Authors so that you can use it instead in your query string.

We highly recommend that you contact the creators of the Co-Authors plugin and asked them what is the custom field for the the Authors or you also can ask them how you can create a custom query string while their plugin is active. They should be able to help you in resolving your Looper Provider Query String issue since they are more familiar with this plugin.

Thank you for your understanding.

Exactly what I figured, thanks for the verification! I’ll explore Option 2 a bit first before circling back. To that end…

…can you provide a use case on here that demonstrates using a post’s relational fields (ACF) to provide looper output? I’m unsure how that might look like in terms of a query string.

Hi @Rule72,

I would suggest you go through the following article, which may help you with this.


https://theme.co/forum/t/new-looper-providers-acf-repeater-field/84558/8

Thanks

1 Like

Thanks @tristup ! I’ll explore those for this second option and report what works/doesn’t work back here for completeness/documentation.

Hey @Rule72,

Great and let us know how it goes on your end.

Thank you.

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