ryanwelcher / advanced-query-loop

WordPress plugin that introduces a Query Loop block variation that can create advanced queries.
87 stars 10 forks source link

Add Current Post Exclusion #24

Closed Pulsar-X closed 11 months ago

Pulsar-X commented 1 year ago

This PR implements two things:

  1. The possibility to specify posts that should be excluded from the query by their title.
  2. An option to exclude the current post from the query.

This works across multiple Post Types.

To accomplish this, two new attributes were introduced:

  1. exclude_posts: An array of post IDs that should be excluded
  2. exclude_current: The current post ID, if it should be excluded, or 0, if not.

In an initial implementation, exclude_current was a boolean. I unfortunately found no way to access the current post ID in the context of the rest_post_query filter for the preview in the block editor (query-loop.php, ln. 238). Now the current ID just gets passed as an attribute.

If you have any idea how to implement this without passing the current post ID, please feel free to modify my solution.

I am quite new to WordPress development, so if I have committed any blunders, please point them out.

Closes #3

ryanwelcher commented 1 year ago

This is really nice addition and thanks for putting it together!

Would it be possible for you to split these out into two PRs; one for the current post exclude and the other for excluding a list of posts?

I'd love to land excluding the current post pretty quickly but I'd like to think about the list of posts a little as it can be a pretty expensive query.

Great work!

Pulsar-X commented 11 months ago

@ryanwelcher I apologize for taking so long to fix this up.

I have removed everything that concerns excluding a list of posts, leaving only the functionality to exclude the current post with a toggle switch.

I'll open another PR soon to add the missing functionality back in.

Please let me know if I should change anything else.

ryanwelcher commented 11 months ago

This is a great addition! Thanks for splitting it out. I am 99% sure I'll merge the other part but just wanted to think about it before as it could mean an expensive query.