Skip to content

Instantly share code, notes, and snippets.

@cryptexvinci
Created May 25, 2021 02:31
Show Gist options
  • Save cryptexvinci/274c7b8cb48a3818c09dd7d55cd79144 to your computer and use it in GitHub Desktop.
Save cryptexvinci/274c7b8cb48a3818c09dd7d55cd79144 to your computer and use it in GitHub Desktop.
How to let a profile tab display posts published in a certain category by this user?
<?php
add_action('um_profile_menu', 'um_profile_content_posts_custom_cat');
function um_profile_content_posts_custom_cat(){
$active_tab = UM()->profile()->active_tab();
if ($active_tab == 'posts') {
$latest = new WP_Query( array (
'post_type' => array('post'),
'author' => um_user( 'ID' )
));
$post_ids = wp_list_pluck( $latest->posts, 'ID' );
echo '<div class="um-profile-nav">';
foreach( $post_ids as $post_id ){
$data = (get_the_category($post_id));
?>
<div class="um-profile-nav-item um-profile-nav-main ">
<a href="<?php echo get_category_link($data[0]->cat_ID);?>">
<?php echo $data[0]->cat_name;?>
</a>
</div>
<?php
}
echo '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment