Does L&L support transient and/or excusion for duplicate posts showing on the same page?

Hi from Greece! Super new here, and very, very excited about this project, it could speed my coding time to to the sky!

I have two small questions, i’ve tried to find the code in the documentation, but i failed - sorry for your time, if its there and i missed it:

One, does L&L have any code for Transient save and retrieve? Just to speed things up when showing large amount of content!

Two, does L&L have any code for duplicates? In most of my sites, normally i’ll have to write exta wordpress code to exclude a post from showing multiple times if its already printed on the same page in different blocks. Is this possible with L&L?

Thanks again for your time - and again sorry if my questions are already aswered in the documentation :slight_smile:

Hi from Canada! Glad to hear that you’re excited about the project. If you manage to build it into your workflow, I’m sure many people on this forum would love to hear what types of templates you build to improve your site-building workflow!

I’m a PHP noob so you’ll have to forgive my ignorance because I’m not totally sure what you’re asking haha! Sounds like the various variables built into L&L might have what you’re looking for? You can pass data between L&L templates using local variables and you can even load up entire templates within other templates using the template variable. If you need to save data to reference it later, you could use the map or list variable depending on how complex the data is that you’re wanting to save. Lots of tools to work with in there.

I don’t think there’s anything explicitly for that, but if you’re looping through posts with the Loop tag, you could use the exclude query parameter to exclude posts by ID. You’d need to find some way of letting L&L know which post IDs to exclude but you could probably do that with some of the variables linked above.

Happy looping!

1 Like

Hey Benjamin!

So, to make this clear, WP has a function named Transient. What it does is to save the results of a query in a temporary database cell, that can be retrieved to be printed untill is expired. See more here: Transients | Common APIs Handbook | WordPress Developer Resources This way, they are less calls to the database for results that don’t change often, like menus, and the site goes a lot faster!

I will check ASAP the local variables to see if they can help on my task.

Thanks again for your time!

Ah, understood. It sounds like a query variable is what you’re looking for then

@benjamin transients and variables are only similar in that they’re both ways to avoid unnecessary extra queries. Transients are cached queries usually stored in the wp_options table.

L&L doesn’t currently have a way to directly access transients as far as I’m aware, but @giannis you may be interested in the Cache and Async tags if your environment is set up for object caching

1 Like

Thank you @julia - i will check them out!

Welcome Giannis,

There is an exclude parameter for most loop types. I imagine you could create some logic that checks for an already displayed post ID on the page and excludes it from the loop.

Perhaps you can create a list of post IDs that are already displayed on the page and then do a comparison within a post loop to exclude them.

I use this to exclude the currently displayed single post from a ‘More Posts’ feature:

<Loop type="post" count="3" orderby="date" order="desc" exclude="{Field id}">
    <Field title />
</Loop>

Also, this reusable posts demo might be helpful in understanding how L&L can speed up your development:

With regards to performance, personally, I use Lightspeed cache (Advanced setting) and can achieve scores in the 90s on Google PageSpeed Test, but my sites are fairly simple with minimal plugins running.

1 Like

Thank you @Rips - the exclude seems to be exactly what i need. Now I’ll have to figure out if i can, and how, to pass a variable of excluded ids between multiple blocks on the same page.

Thanks again!

1 Like

I’m pretty sure regular L&L variables exist for the duration of the page load, so if you know which block is going to load first you could just set the variable in that block and load it up in the others. If you’re not sure which block is going to load first, you could use the If tag to check if the variable has already set. Or if you want to exclude more and more stuff each time you display some posts, you could just keep appending stuff to a list variable each time you display some posts. Lots of approaches here.

Thanks for clarifying that! Je vais me coucher moins niaiseux à soir :slight_smile:

2 Likes