From 6beefaf2eb22ab890da91f7f536ae2a5d1de0a17 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Mon, 19 Feb 2024 17:52:15 +0530 Subject: [PATCH 1/2] improve the logic to support custom taxonomies --- src/Includes/Filters.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Includes/Filters.php b/src/Includes/Filters.php index f4d680b6..58c3ea6b 100644 --- a/src/Includes/Filters.php +++ b/src/Includes/Filters.php @@ -111,15 +111,23 @@ public function maybe_add_custom_params( $params ) { $params .= " event-author='$author_name'"; } - $categories = get_the_category( $post->ID ); + // Add support for post category and tags along with custom taxonomies. + $taxonomies = get_object_taxonomies( $post->post_type ); - if ( ! is_array( $categories ) ) { - return $params; - } + // Loop through existing taxonomies. + foreach ( $taxonomies as $taxonomy ) { + $terms = get_the_terms( $post->ID, $taxonomy ); + + // Skip the iteration, if `$terms` is not array. + if ( ! is_array( $terms ) ) { + continue; + } - foreach ( $categories as $category ) { - if ( $category instanceof WP_Term ) { - $params .= " event-category='$category->name'"; + // Loop through the terms. + foreach ( $terms as $term ) { + if ( $term instanceof WP_Term ) { + $params .= " event-{$taxonomy}='{$term->name}'"; + } } } From 4a44d17756e8bc05a59f3487a1be3100bcbd3fd3 Mon Sep 17 00:00:00 2001 From: Dan0sz <18595395+Dan0sz@users.noreply.github.com> Date: Fri, 17 May 2024 14:02:10 +0200 Subject: [PATCH 2/2] Fixed syntax errors after merge conflict. --- src/Filters.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Filters.php b/src/Filters.php index d4e4f7bc..7262491a 100644 --- a/src/Filters.php +++ b/src/Filters.php @@ -7,7 +7,7 @@ * @subpackage Plausible Analytics */ -namespace Plausible\Analytics\WP\Includes; +namespace Plausible\Analytics\WP; use WP_Term; use Exception; @@ -123,7 +123,7 @@ public function maybe_add_custom_params( $params ) { // Skip the iteration, if `$terms` is not array. if ( ! is_array( $terms ) ) { - continue // @codeCoverageIgnore; + continue; // @codeCoverageIgnore; } // Loop through the terms.