From 2793d99d7ce97ac5c7c1ea9bb721c0795a68a3c4 Mon Sep 17 00:00:00 2001 From: Chris Abraham Date: Mon, 21 Oct 2024 15:29:51 -0400 Subject: [PATCH] Enable filtering posts by year Signed-off-by: Chris Abraham --- .../lf-mu/admin/class-lf-mu-admin.php | 25 +++++++++++++++++++ .../lf-mu/includes/class-lf-mu.php | 1 + 2 files changed, 26 insertions(+) diff --git a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/class-lf-mu-admin.php b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/class-lf-mu-admin.php index 5425494b..60c6fac5 100644 --- a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/class-lf-mu-admin.php +++ b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/admin/class-lf-mu-admin.php @@ -157,6 +157,19 @@ public function validate( $input ) { // This command used to tag all blog posts with projects when you save the settings in the admin. // $this->tag_blog_posts_with_projects(); // phpcs:ignore. + $myposts = get_posts( + array( + 'post_type' => 'post', + 'posts_per_page' => -1, + 'category' => 230, + ) + ); + foreach ( $myposts as $post ) { + $year = get_post_time( 'Y', false, $post ); + update_post_meta( $post->ID, 'lf_post_published_year', $year ); + } + wp_reset_postdata(); + $options = get_option( $this->plugin_name ); $options['show_hello_bar'] = ( isset( $input['show_hello_bar'] ) && ! empty( $input['show_hello_bar'] ) ) ? 1 : 0; @@ -343,6 +356,18 @@ public function set_case_study_year( $post_id, $post, $update ) { update_post_meta( $post_id, 'lf_case_study_published_year', $year ); } + /** + * Set meta data of year for blog posts to faciliate filtering + * + * @param int $post_id Post ID. + * @param object $post Post object. + * @param bool $update Whether this is an existing post being updated. + */ + public function set_post_year( $post_id, $post, $update ) { + $year = get_post_time( 'Y', false, $post ); + update_post_meta( $post_id, 'lf_post_published_year', $year ); + } + /** * Sync programs from https://community.cncf.io/ */ diff --git a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php index 8a2a347e..b50be82f 100644 --- a/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php +++ b/web/wp-content/mu-plugins/wp-mu-plugins/lf-mu/includes/class-lf-mu.php @@ -168,6 +168,7 @@ private function define_admin_hooks() { $this->loader->add_action( 'save_post_lf_case_study', $plugin_admin, 'set_case_study_year', 10, 3 ); $this->loader->add_action( 'save_post_lf_case_study_cn', $plugin_admin, 'set_case_study_year', 10, 3 ); $this->loader->add_action( 'save_post_lf_report', $plugin_admin, 'set_report_year', 10, 3 ); + $this->loader->add_action( 'save_post_post', $plugin_admin, 'set_post_year', 10, 3 ); // Sync projects with landscape. $this->loader->add_action( 'lf_sync_projects', $plugin_admin, 'sync_projects' );