| 1 |
<?php |
| 2 |
/** |
| 3 |
* Temporary compatibility code for new functionalities/changes related to the query block. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Filters the query loop block query vars to exclude the current post. |
| 10 |
* |
| 11 |
* @param array $query The current query vars. |
| 12 |
* @param WP_Block $block The block instance. |
| 13 |
* |
| 14 |
* @return array The modified query vars. |
| 15 |
*/ |
| 16 |
function gutenberg_filter_query_block_exclude_current( $query, $block ) { |
| 17 |
if ( ! empty( $block->context['query']['excludeCurrent'] ) ) { |
| 18 |
$current_post_id = get_the_ID(); |
| 19 |
if ( $current_post_id ) { |
| 20 |
$query['post__not_in'][] = $current_post_id; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
return $query; |
| 25 |
} |
| 26 |
|
| 27 |
add_filter( 'query_loop_block_query_vars', 'gutenberg_filter_query_block_exclude_current', 10, 2 ); |
| 28 |
|