httpRequest = $httpRequest; $this->orderRepository = $orderRepository; } /** * Registers service. * * @return void */ public function register(): void { add_filter( 'posts_clauses', [ $this, 'processPostClauses' ], 10, 2 ); } /** * Extends WP_Query to include custom table. * * @link https://wordpress.stackexchange.com/questions/50305/how-to-extend-wp-query-to-include-custom-table-in-query * * @param array $clauses Clauses. * @param \WP_Query $queryObject WP_Query. * * @return array */ public function processPostClauses( array $clauses, \WP_Query $queryObject ): array { $paramValues = [ 'packetery_carrier_id' => null, 'packetery_to_submit' => null, 'packetery_to_print' => null, 'packetery_order_type' => null, ]; foreach ( $paramValues as $key => $value ) { $paramValues[ $key ] = $this->getParamValue( $queryObject, $key ); } return $this->orderRepository->processPostClauses( $clauses, $queryObject, $paramValues ); } /** * Gets parameter value from GET data or WP_Query. * * @param \WP_Query $queryObject WP_Query. * @param string $key Key. * * @return mixed|null */ private function getParamValue( \WP_Query $queryObject, $key ) { $get = $this->httpRequest->getQuery(); if ( isset( $get[ $key ] ) && '' !== (string) $get[ $key ] ) { return $get[ $key ]; } if ( isset( $queryObject->query[ $key ] ) && '' !== (string) $queryObject->query[ $key ] ) { return $queryObject->query[ $key ]; } return null; } }