From 73abab79ae13aea1935935d7fca4163aa3e5ce85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Santos?= Date: Wed, 7 Sep 2022 10:53:52 +0100 Subject: [PATCH] Additional filters for the Post UI queries --- includes/UI/PostToPost.php | 16 +++++++++++++--- includes/UI/PostToUser.php | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/includes/UI/PostToPost.php b/includes/UI/PostToPost.php index 58a77b8..67bd134 100644 --- a/includes/UI/PostToPost.php +++ b/includes/UI/PostToPost.php @@ -22,9 +22,9 @@ public function filter_data( $data, $post ) { $final_posts = array(); $args = array( - 'post_type' => (array) $other_post_type, + 'post_type' => (array) $other_post_type, 'relationship_query' => array( - 'name' => $this->relationship->name, + 'name' => $this->relationship->name, 'related_to_post' => $post->ID, ), ); @@ -33,6 +33,16 @@ public function filter_data( $data, $post ) { $args['orderby'] = 'relationship'; } + /** + * Filters the Post UI query args. + * + * @since 1.6.0 + * @param array $args The \WP_Query args. + * @param \WP_Post $post The post object. + * @return array + */ + $args = apply_filters( 'tenup_content_connect_post_ui_query_args', $args, $post ); + $query = new \WP_Query( $args ); if ( $query->have_posts() ) { @@ -40,7 +50,7 @@ public function filter_data( $data, $post ) { $post = $query->next_post(); $final_post = array( - 'ID' => $post->ID, + 'ID' => $post->ID, 'name' => $post->post_title, ); diff --git a/includes/UI/PostToUser.php b/includes/UI/PostToUser.php index 55a1dbf..ba3cac3 100644 --- a/includes/UI/PostToUser.php +++ b/includes/UI/PostToUser.php @@ -20,7 +20,7 @@ public function filter_data( $data, $post ) { $args = array( 'relationship_query' => array( - 'name' => $this->relationship->name, + 'name' => $this->relationship->name, 'related_to_post' => $post->ID, ), ); @@ -29,6 +29,16 @@ public function filter_data( $data, $post ) { $args['orderby'] = 'relationship'; } + /** + * Filters the Post UI user query args. + * + * @since 1.6.0 + * @param array $args The \WP_User_Query args. + * @param \WP_Post $post The post object. + * @return array + */ + $args = apply_filters( 'tenup_content_connect_post_ui_user_query_args', $args, $post ); + $query = new \WP_User_Query( $args ); $users = $query->get_results(); @@ -36,7 +46,7 @@ public function filter_data( $data, $post ) { foreach ( $users as $user ) { $final_user = array( - 'ID' => $user->ID, + 'ID' => $user->ID, 'name' => $user->display_name, );