-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove globally defined $post variable #388
Comments
It gets much harder to exclude current post this using post_not_in argument (you have to fetch n+1 and then filter it out IF you got the current post back from the query, if not then you have to stop before the last one or you will show 1 extra post). So that small performance penalty is fine imo. And even then you somehow need to know the current post ID. If you're more worried about using a global variable inside a block, we could just use Dunno I'd leave it as it is, don't think it's too big of a deal to have a global var in and it makes the implementation of excluding current post feature simpler. |
I'd like to investigate the behavior of this global object here. In general we should definitely avoid using globals as much as possible (you never know what you may get, or if the global post can be changed and affect the results somehow). As for complexity, the example in the link doesn't seem to be that complex, and you can just pass the current ID when building the custom query and rendering related posts. Not sure what the performance penalty is, I'll try to play a bit and see the results using query monitor 👍🏼 EDIT: A more in-depth explanation of why |
@infinum/wordpress-team what's the final decision for this? Do we keep the global Do we drop the |
If it's a big change that would take a couple of hours/days to implement I'd say, for now, leave it as is. We can optimize this in the projects later on. And I don't think that it's a BC break even if we change it down the line, no? I'd definitely like it to be as performant as possible. |
While reviewing a PR I've noticed this part
eightshift-frontend-libs/blocks/init/src/Blocks/custom/featured-posts/featured-posts.php
Lines 20 to 23 in beb0937
In the featured posts block.
I'm not sure what is this doing here tbh. @moonbyt3 suggested that this can be used on a single page, probably when we want to exclude the current post from the related posts
But this is not something we should do in the first place.
So I think this should be removed. The logic for querying posts is usually added via filter IIRC inside a special class, so all the querying and PHP filtering can be done that way.
@infinum/wordpress-team thoughts, suggestions, well wishes? 😄
The text was updated successfully, but these errors were encountered: