Recent

Query_ModifierclassPro only

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: 94

public function get_weights( $args ): array;
Type Name Description
array $args Query arguments.

Returns: array — Array of weights.

get_source_data()

Get source post data from custom table.

Since: 4.0.0
Line: 145

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: 213

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: 264

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: 381

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: 432

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: 557

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: 615

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.

query_posts_groupby()

Update the groupby clause.

Since: 4.0.0
Line: 706

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: 726

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: 778

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: 802

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: 820

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: 843

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: 870

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: 883

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: 932

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: 979

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: 1030

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.