Query_Modifier
Class to modify CRP_Query with Pro features.
Namespace: WebberZone\Contextual_Related_Posts\Pro
Since: 4.0.0
Source: includes/pro/class-query-modifier.php line 25
Methods
__construct()
Constructor
Line: 59
public function __construct( ?Custom_Tables\Custom_Tables $custom_tables );
| Type | Name | Description |
|---|---|---|
Custom_Tables\Custom_Tables|null |
$custom_tables |
Custom Tables instance. |
hooks()
Register hooks
Since: 4.0.0
Line: 71
public function hooks( );
get_weights()
Get the weights for the title, content, excerpt, taxonomies and primary boost.
Since: 4.0.0
Line: 95
public function get_weights( $args ): array;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: array — Array of weights.
get_recency_settings() static
Resolve the recency boost settings, clamped to their valid ranges.
Since: 4.5.0
Line: 130
static public function get_recency_settings( array $args = ... ): array;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: array — float, halflife: float} Boost percentage and half-life in days.
is_relevance_ordered() static
Whether a query is ordered by relevance rather than an explicit column.
Since: 4.5.0
Line: 148
static public function is_relevance_ordered( array $args = ... ): bool;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: bool — True when results are ranked by the relevance score.
is_recency_boost_active() static
Whether the recency boost is active for this query.
Since: 4.5.0
Line: 177
static public function is_recency_boost_active( array $args = ... ): bool;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: bool — True when an age-decayed multiplier should be applied to the ordering.
get_recency_sql() static
Build the age-decay multiplier applied to the relevance score in ORDER BY.
Emits (1 + b * COALESCE(1 / (1 + age_days / halflife), 0)), which multiplies the raw
relevance score in ordering only. The reference date is supplied by PHP rather than NOW()
so the SQL text stays stable for the whole cache window. A NULL or zero date yields a
decay term of 0, i.e. no boost rather than a NULL score.
Since: 4.5.0
Line: 197
static public function get_recency_sql( string $date_column, array $args = ... ): string;
| Type | Name | Description |
|---|---|---|
string |
$date_column |
Fully qualified UTC date column, e.g. wp_posts.post_date_gmt. |
array |
$args |
Query arguments. |
Returns: string — SQL expression, or an empty string when the boost is off or unsupported.
get_recency_cache_cap() static
Maximum lifetime for a result set cached under a recency-boosted ordering.
The cap has to match the granularity of the reference date the decay is measured against, otherwise the extra refreshes either return identical ordering or the ordering goes stale.
Since: 4.5.0
Line: 247
static public function get_recency_cache_cap( array $args = ... ): int;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: int — Cap in seconds, 0 when the boost is inactive.
get_recency_orderby() static
Apply the recency multiplier to a bare relevance-ordering expression.
Since: 4.5.0
Line: 267
static public function get_recency_orderby( string $score_column, string $date_column, array $args = ... ): string;
| Type | Name | Description |
|---|---|---|
string |
$score_column |
Score column or alias, e.g. score. |
string |
$date_column |
UTC date column the decay is measured from. |
array |
$args |
Query arguments. |
Returns: string — Ordering expression including the trailing direction.
get_source_data()
Get source post data from custom table.
Since: 4.0.0
Line: 302
public function get_source_data( WP_Post $source_post ): object|null;
| Type | Name | Description |
|---|---|---|
\WP_Post |
$source_post |
Source post object. |
Returns: object|null — Source post data from custom table or null if not found.
get_custom_table_content_clauses()
Get content match clauses for custom tables.
Since: 4.0.0
Line: 370
public function get_custom_table_content_clauses( stdClass $source_data, array $weights, array $args ): array;
| Type | Name | Description |
|---|---|---|
\stdClass |
$source_data |
{ |
array |
$weights |
Array of weights for content fields. |
array |
$args |
Arguments array. |
Returns: array — Array of content match clauses.
get_custom_table_taxonomy_clauses()
Process custom table taxonomy matches and return taxonomy clauses for relevance calculation.
Since: 4.0.0
Line: 421
public function get_custom_table_taxonomy_clauses( object $source_data, array $weights, array $args ): array;
| Type | Name | Description |
|---|---|---|
object |
$source_data |
Source post data from custom table. |
array |
$weights |
Array of weights for taxonomies. |
array |
$args |
Arguments array. |
Returns: array — Array containing taxonomy clauses and data.
get_wp_content_clauses()
Get content match clauses for WordPress posts table.
Since: 4.0.0
Line: 538
public function get_wp_content_clauses( WP_Post $source_post, array $weights, array $args ): array;
| Type | Name | Description |
|---|---|---|
\WP_Post |
$source_post |
Source post object. |
array |
$weights |
Array of weights for content fields. |
array |
$args |
Arguments array. |
Returns: array — Array of content match clauses.
get_taxonomy_match_clauses()
Process taxonomy matches and return taxonomy clauses for relevance calculation.
Since: 4.0.0
Line: 589
public function get_taxonomy_match_clauses( WP_Post $source_post, array $weights ): array;
| Type | Name | Description |
|---|---|---|
\WP_Post |
$source_post |
Source post object. |
array |
$weights |
Array of weights for taxonomies. |
Returns: array — Array containing taxonomy clauses and data.
query_posts_fields()
Modify the posts_fields clause.
Since: 4.0.0
Line: 714
public function query_posts_fields( $fields, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$fields |
The SELECT clause of the query. |
\WP_Query|\CRP_Query |
$query |
The WP_Query or CRP_Query instance. |
CRP_Core_Query |
$instance |
The CRP_Core_Query instance. |
Returns: string — Updated Fields
query_posts_where_match()
Modify the MATCH clause of the WHERE clause to filter relevant posts.
Since: 4.0.0
Line: 772
public function query_posts_where_match( $match_clause, $where, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$match_clause |
The MATCH section of the WHERE clause of the query. |
string |
$where |
The WHERE clause of the query. |
\WP_Query|\CRP_Query |
$query |
The WP_Query or CRP_Query instance. |
CRP_Core_Query |
$instance |
The CRP_Core_Query instance. |
Returns: string — Modified MATCH clause of the WHERE clause.
is_relevance_ranked_pool()
The recency boost ranks on a multiplied score, so the pool is not ordered by the score column.
Since: 4.5.0
Line: 844
public function is_relevance_ranked_pool( $ranked, $instance ): bool;
| Type | Name | Description |
|---|---|---|
bool |
$ranked |
Whether the pool is ranked by score. |
\WebberZone\Contextual_Related_Posts\CRP_Core_Query |
$instance |
The CRP_Core_Query instance. |
Returns: bool — Whether the pool is ranked by score.
query_posts_groupby()
Update the groupby clause.
Since: 4.0.0
Line: 880
public function query_posts_groupby( $groupby ): string;
| Type | Name | Description |
|---|---|---|
string |
$groupby |
The current groupby clause. |
Returns: string — Updated groupby clause.
query_posts_orderby_clauses()
Update the orderby clauses for CRP queries.
Since: 3.5.2
Line: 902
public function query_posts_orderby_clauses( $orderby_clauses, $query, $instance ): array;
| Type | Name | Description |
|---|---|---|
array |
$orderby_clauses |
Array of clauses. |
\WP_Query|\CRP_Query |
$query |
The WP_Query or CRP_Query instance. |
CRP_Core_Query |
$instance |
The CRP_Core_Query instance (optional). |
Returns: array — Updated array of clauses.
query_posts_orderby()
Swap the core match SQL for the pro weighted score in the final ORDER BY clause.
Since: 4.4.0
Line: 964
public function query_posts_orderby( $orderby, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$orderby |
The ORDER BY clause of the query. |
\WP_Query|\CRP_Query |
$query |
The WP_Query or CRP_Query instance. |
CRP_Core_Query |
$instance |
The CRP_Core_Query instance. |
Returns: string — Updated ORDER BY clause.
find_approximate_index()
Find the approximate index of a substring in an array of strings.
Since: 3.5.2
Line: 1009
public function find_approximate_index( $input_array, $substring ): int|bool;
| Type | Name | Description |
|---|---|---|
array |
$input_array |
Array of strings. |
string |
$substring |
Substring to search for. |
Returns: int|bool — Index of the substring in the array.
update_crp_query_args_before()
Update the CRP query args before the query is run.
Since: 3.5.0
Line: 1027
public function update_crp_query_args_before( $args, $source_post ): array;
| Type | Name | Description |
|---|---|---|
array |
$args |
The query arguments. |
\WP_Post |
$source_post |
The source post. |
Returns: array — Updated query arguments.
custom_table_join()
Modify the JOIN clause to include our custom tables.
Since: 4.0.0
Line: 1050
public function custom_table_join( $join ): string;
| Type | Name | Description |
|---|---|---|
string |
$join |
The JOIN clause of the query. |
Returns: string — Modified join.
should_use_custom_tables()
Determine if we should use custom tables for queries.
Since: 4.0.0
Line: 1077
public function should_use_custom_tables( ): bool;
Returns: bool — True if custom tables should be used.
use_precomputed_tax_score()
Determine if the precomputed custom-table tax_score should be used.
Since: 4.4.0
Line: 1090
public function use_precomputed_tax_score( ): bool;
Returns: bool — True if the precomputed tax_score should be used.
query_posts_join()
Modify the posts_join clause for taxonomy weightage.
Since: 4.0.0
Line: 1139
public function query_posts_join( $join, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$join |
The JOIN clause of the query. |
\WP_Query |
$query |
The WP_Query instance. |
CRP_Core_Query |
$instance |
The CRP_Core_Query instance. |
Returns: string — Updated JOIN clause.
add_max_execution_time()
Adds MAX_EXECUTION_TIME hint to MySQL queries.
Since: 4.0.0
Line: 1186
public function add_max_execution_time( $sql, $query ): string;
| Type | Name | Description |
|---|---|---|
string |
$sql |
The complete SQL query. |
\WP_Query |
$query |
The WP_Query instance. |
Returns: string — Modified SQL query with MAX_EXECUTION_TIME hint.
add_cornerstone_posts()
Add cornerstone posts to the related posts list.
Hooked on crp_query_the_posts (inside CRP_Core_Query::the_posts), which fires after the pool has been sliced to $limit and after the cache has been written. This ensures cornerstone posts are never baked into the persistent cache, the inflated buffer used for PHP exclusions is not destroyed prematurely, and the final post count always equals $limit.
Since: 4.0.0
Line: 1237
public function add_cornerstone_posts( $posts, $args, $query, $instance ): array;
| Type | Name | Description |
|---|---|---|
array |
$posts |
Array of post objects (already sliced to limit). |
array |
$args |
CRP query arguments. |
\WP_Query |
$query |
The WP_Query instance. |
\WebberZone\Contextual_Related_Posts\CRP_Core_Query |
$instance |
The CRP_Core_Query instance. |
Returns: array — Modified array of post objects.