Query_Modifier
Class to modify CRP_Query with Pro features.
Namespace: WebberZone\Contextual_Related_Posts\Pro
Since: 4.0.0
Source: includes/class-query-modifier.php line 25
Methods
__construct()
Constructor
Line: 41
public function __construct( Custom_Tables\Custom_Tables $custom_tables );
| Type | Name | Description |
|---|---|---|
Custom_Tables\Custom_Tables | $custom_tables | Custom Tables instance. |
hooks()
Register hooks
Since: 4.0.0
Line: 53
public function hooks( );
get_weights()
Get the weights for the title, content, excerpt, taxonomies and primary boost.
Since: 4.0.0
Line: 75
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: 126
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: 187
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: 238
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: 356
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: 407
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: 524
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: 580
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: 689
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: 709
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.
find_approximate_index()
Find the approximate index of a substring in an array of strings.
Since: 3.5.2
Line: 757
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: 775
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: 798
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: 825
public function should_use_custom_tables( ): bool;
Returns: bool — True if custom tables should be used.
query_posts_join()
Modify the posts_join clause for taxonomy weightage.
Since: 4.0.0
Line: 839
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: 879
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.
- The final post count always equals $limit.
Since: 4.2.4
Line: 930
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.