Skip to content

Commit

Permalink
List the related blog post on a Kubestronaut profile (#919)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Abraham <[email protected]>
  • Loading branch information
cjyabraham committed Feb 5, 2025
1 parent 82be9b3 commit d8bd42c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,38 @@ public function set_post_year( $post_id, $post, $update ) {
update_post_meta( $post_id, 'lf_post_published_year', $year );
}

/**
* If post is a Kubestronaut feature then save post ID as a related post on Kubestronaut.
*
* @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_related_post( $post_id, $post, $update ) {

$post_title = get_the_title( $post_id );
if ( 'publish' !== $post->post_status || strpos( $post_title, 'Kubestronaut in Orbit:' ) === false ) {
return;
}

$kubestronaut_name = trim( str_replace( 'Kubestronaut in Orbit:', '', $post_title ) );

$query = new WP_Query(
array(
'post_type' => 'lf_person',
'post_status' => 'publish',
'posts_per_page' => 1,
'title' => $kubestronaut_name,
)
);
if ( $query->have_posts() ) {
$query->the_post();
update_post_meta( get_the_ID(), 'lf_related_post', $post_id );
}

wp_reset_postdata();
}

/**
* Sync programs from https://community.cncf.io/
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ private function define_admin_hooks() {
$this->loader->add_action( 'admin_head', $plugin_admin, 'change_adminbar_colors' );
$this->loader->add_action( 'wp_head', $plugin_admin, 'change_adminbar_colors' );
$this->loader->add_action( 'rest_api_init', $plugin_admin, 'register_lf_rest_routes' );
$this->loader->add_action( 'save_post_post', $plugin_admin, 'set_related_post', 10, 3 );

// Hook to save year in a meta fields for filtering.
$this->loader->add_action( 'save_post_lf_case_study', $plugin_admin, 'set_case_study_year', 10, 3 );
Expand Down
12 changes: 12 additions & 0 deletions web/wp-content/themes/cncf-twenty-two/components/people-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
$certdirectory = get_post_meta( get_the_ID(), 'lf_person_certdirectory', true );
$image_url = get_post_meta( get_the_ID(), 'lf_person_image', true );
$location = get_post_meta( get_the_ID(), 'lf_person_location', true );
$related_post = get_post_meta( get_the_ID(), 'lf_related_post', true );
$languages = get_the_terms( get_the_ID(), 'lf-language' );
$projects = get_the_terms( get_the_ID(), 'lf-project' );
$content = get_the_content();
Expand Down Expand Up @@ -311,6 +312,17 @@ class="person__pronouns">(<?php echo esc_html( $pronouns ); ?>)</span>
</li>
<?php
}

if ( $related_post ) {
?>
<li><strong>Related Post:</strong>
<?php
// Display related post.
echo '<a href="' . esc_url( get_permalink( $related_post ) ) . '">' . esc_html( get_the_title( $related_post ) ) . '</a>';
?>
</li>
<?php
}
?>
</ul>
<?php endif; ?>
Expand Down

0 comments on commit d8bd42c

Please sign in to comment.