Skip to content

Commit

Permalink
Enable filtering posts by year
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Abraham <[email protected]>
  • Loading branch information
cjyabraham committed Oct 21, 2024
1 parent 38d2697 commit 2793d99
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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/
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down

0 comments on commit 2793d99

Please sign in to comment.