Skip to content

feat: exclude current post from query#155

Open
laravdiemen wants to merge 1 commit into
mainfrom
feat/exclude-current-post
Open

feat: exclude current post from query#155
laravdiemen wants to merge 1 commit into
mainfrom
feat/exclude-current-post

Conversation

@laravdiemen
Copy link
Copy Markdown
Contributor

Het query blok toont nu ook de huidige pagina waarop je zit. Dat is onnodig want als je er dan op klikt, dan komt je weer precies bij dezelfde pagina uit. Ik heb er een apply_filters omheen gezet zodat je het eventueel via je thema wel kan overschrijven.

Copilot AI review requested due to automatic review settings May 27, 2026 12:40
@laravdiemen laravdiemen requested a review from a team as a code owner May 27, 2026 12:40
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 27, 2026

Coverage report for commit: 94a470c
File: coverage.xml

Cover ┌─────────────────────────┐ Freq.
   0% │ ███████████████████████ │ 42.9%
  10% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  20% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  30% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  40% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  50% │ ████████░░░░░░░░░░░░░░░ │ 14.3%
  60% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  70% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  80% │ ░░░░░░░░░░░░░░░░░░░░░░░ │  0.0%
  90% │ ████████░░░░░░░░░░░░░░░ │ 14.3%
 100% │ ████████████████░░░░░░░ │ 28.6%
      └─────────────────────────┘
 *Legend:* █ = Current Distribution 
Summary - Lines: 29.43% | Methods: 58.18%
FilesLinesMethodsBranches
src/Block
   Block.php--100.00%
   BlockAttributes.php92.86%93.75%100.00%
src/Casts
   IntCast.php50.00%-100.00%
src/Query
   PostQuery.php--100.00%
   QueryInterface.php100.00%100.00%100.00%
src
   QueryBlockServiceProvider.php--100.00%
src/Traits
   Helpers.php100.00%100.00%100.00%

🤖 comment via lucassabreu/comment-coverage-clover

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the query block so it excludes the currently viewed post from automatic query results by default, while allowing projects to opt out via a PHP filter.

Changes:

  • Adds yard_query_block_exclude_current_post filter around the default exclusion behavior.
  • Adds logic to detect the current post ID and append an ID != current constraint.
  • Skips exclusion for manual selections and sticky-post cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Query/PostQuery.php Outdated
Comment thread src/Query/PostQuery.php
@laravdiemen laravdiemen force-pushed the feat/exclude-current-post branch from 2e8de36 to 94a470c Compare May 27, 2026 13:09
Comment thread src/Query/PostQuery.php
private function currentPostId(): int
{
if (function_exists('get_the_ID') && $id = get_the_ID()) {
return $id;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return $id; -> return $id;

Comment thread src/Query/PostQuery.php
}

if (function_exists('get_queried_object_id')) {
return get_queried_object_id();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Voor de zekerheid misschien:
return (int) get_queried_object_id();

Comment thread src/Query/PostQuery.php
*
* This applies when the query is not using a manual selection and the current post is not the configured sticky post.
*
* @param bool $excludeCurrentPost Whether to exclude the current post from the query results. Default true.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik weet niet of ik de @param en @return echt zinvol vindt en tussen de 2e eerste regels staan wat mij betreft een enter teveel. 🐜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants