Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Query/PostQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ public function get(): Collection
->limit($this->attributes->limit())
->offset($this->attributes->offset());

Comment thread
laravdiemen marked this conversation as resolved.
/**
* Filters whether the current post should be excluded from query results.
*
* 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. 🐜

*
* @return bool Whether to exclude the current post from the query results.
*/
$excludeCurrentPost = apply_filters('yard_query_block_exclude_current_post', true);

$currentPostId = $this->currentPostId();
if (
$excludeCurrentPost &&
! $this->attributes->hasManualSelection() &&
(
! $this->attributes->hasStickyPost() ||
$this->attributes->stickyPostID() !== $currentPostId
) &&
0 < $currentPostId) {
$query->where('ID', '!=', $currentPostId);
}

if ($this->attributes->hasManualSelection()) {
$query->whereIn('ID', $this->attributes->manualSelectionPostIDs());
}
Expand Down Expand Up @@ -175,4 +198,17 @@ private function order(PostBuilder $query): PostBuilder

return $query;
}

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;

}

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();

}

return 0;
}
}
Loading