Skip to content

Instantly share code, notes, and snippets.

@portfola
Last active May 6, 2023 18:15
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save portfola/10750784 to your computer and use it in GitHub Desktop.
Save portfola/10750784 to your computer and use it in GitHub Desktop.
Custom User Taxonomies in WordPress
<?php
/**
* The template for displaying Profile pages.
*
* Used for Artist and Cultural Org "mini" pages.
*
* @package ArtsWestchester
* @since ArtsWestchester 1.0
*/
get_header(); ?>
<?php
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<div id="author-title">
<h1 class="author-title"><?php echo $curauth->display_name;
// Display the badge for Teaching Artists
$terms = wp_get_object_terms( $curauth->ID, 'teaching_artist' );
if ( !empty($terms) ) { ?>
<img id="teaching-artist-badge" src="/wp-content/uploads/2013/09/teaching-artist-badge.png" />
<?php } ?>
</h1>
<?php
// Display the next field only for Cultural Organizations
$role = get_user_meta( $curauth->ID, 'wpaw_capabilities' );
if ( in_array( array('culturalorg' => '1'), $role ) || in_array( array('affiliate' => '1'), $role ) ) {
$org_terms = wp_get_object_terms( $curauth->ID, 'culturalorg' );
if(!empty($org_terms)){
if(!is_wp_error( $org_terms )){
echo '<h2 class="author-cat">category: ';
foreach ($org_terms as $org_term) {
echo '<a href="'.get_term_link($org_term->slug, 'culturalorg').'">'.$org_term->name.'</a><span class="sep">, </span>';
}
echo '</h2>';
}
}
} // End Cultural Org-only section
// Display the next few fields only for Artists and Artist Members
$role = get_user_meta( $curauth->ID, 'wpaw_capabilities' );
if ( in_array( array('artist' => '1'), $role ) || in_array( array('artist_member' => '1'), $role ) ) {
$author_terms = wp_get_object_terms( $curauth->ID, 'artist' );
if(!empty($author_terms)){
if(!is_wp_error( $author_terms )){
echo '<h2 class="author-cat">category: ';
foreach ($author_terms as $author_term) {
echo '<a href="'.get_term_link($author_term->slug, 'artist').'">'.$author_term->name.'</a><span class="sep">, </span>';
}
echo '</h2>';
}
}
} // End Artist-only section ?>
</div><!-- #author-title -->
<div id="profile-carousel" class="owl-carousel" style="float:left">
<?php
$profile_image = get_user_meta( $curauth->ID, 'default_profile_image' );
if ( $profile_image ) {
foreach ( $profile_image as $attachment_id ) {
$link = wp_get_attachment_url( $attachment_id );
$large = wp_get_attachment_image( $attachment_id, 'large', 0, array('class'=>'alignleft') );
printf( '<div><a href="%s">%s</a></div>', $link, $large );
}
}
$slider_file_2 = get_user_meta( $curauth->ID, 'slider_file_2' );
if ( $slider_file_2 ) {
foreach ( $slider_file_2 as $attachment_id ) {
$link = wp_get_attachment_url( $attachment_id );
$large = wp_get_attachment_image( $attachment_id, 'large', 0, array('class'=>'alignleft') );
printf( '<div><a href="%s">%s</a></div>', $link, $large );
}
}
$slider_file_3 = get_user_meta( $curauth->ID, 'slider_file_3' );
if ( $slider_file_3 ) {
foreach ( $slider_file_3 as $attachment_id ) {
$link = wp_get_attachment_url( $attachment_id );
$large = wp_get_attachment_image( $attachment_id, 'large', 0, array('class'=>'alignleft') );
printf( '<div><a href="%s">%s</a></div>', $link, $large );
}
}
$slider_file_4 = get_user_meta( $curauth->ID, 'slider_file_4' );
if ( $slider_file_4 ) {
foreach ( $slider_file_4 as $attachment_id ) {
$link = wp_get_attachment_url( $attachment_id );
$large = wp_get_attachment_image( $attachment_id, 'large', 0, array('class'=>'alignleft') );
printf( '<div><a href="%s">%s</a></div>', $link, $large );
}
}
$slider_file_5 = get_user_meta( $curauth->ID, 'slider_file_5' );
if ( $slider_file_5 ) {
foreach ( $slider_file_5 as $attachment_id ) {
$link = wp_get_attachment_url( $attachment_id );
$large = wp_get_attachment_image( $attachment_id, 'large', 0, array('class'=>'alignleft') );
printf( '<div><a href="%s">%s</a></div>', $link, $large );
}
}
?>
</div><!-- #profile-carousel .owl-carousel -->
<div class="author-body">
<?php // Display the next field only for Cultural Organizations
$role = get_user_meta( $curauth->ID, 'wpaw_capabilities' );
if ( in_array( array('culturalorg' => '1'), $role ) || in_array( array('affiliate' => '1'), $role ) ) { ?>
<h2 class="author-head">Mission Statement</h2>
<div class="author-graf">
<?php echo get_user_meta( $curauth->ID, 'mission', true ); ?>
</div>
<?php } // End Cultural Org-only section ?>
<?php // Display the next few fields only for Artists and Artist Members
$role = get_user_meta( $curauth->ID, 'wpaw_capabilities' );
if ( in_array( array('artist' => '1'), $role ) || in_array( array('artist_member' => '1'), $role ) ) { ?>
<h3 class="author-sub">Contact &amp; Info</h3>
<?php } // End Artists-only statement ?>
<div class="author-contact">
<?php if(get_the_author_meta('user_url', $curauth->ID)): ?>
<p>Website: <a href="<?php the_author_meta('user_url', $curauth->ID); ?>"><?php the_author_meta('user_url', $curauth->ID); ?></a></p>
<?php endif; ?>
<?php if(get_the_author_meta('dbem_phone', $curauth->ID)): ?>
<p>Phone: <?php the_author_meta('dbem_phone', $curauth->ID); ?></li>
<?php endif; ?>
<ul class="profile-social">
<li><a href="mailto:<?php echo $curauth->user_email; ?>"><img src="<?php echo plugins_url() . '/social-sharing-toolkit/images/icons_large/email.png' ?>" alt="<?php echo $curauth->user_email; ?>" title="<?php echo $curauth->user_email; ?>" /></a></li>
<?php if(get_the_author_meta('twitter', $curauth->ID)): ?>
<li><a href="<?php the_author_meta('twitter', $curauth->ID); ?>"><img src="<?php echo plugins_url() . '/social-sharing-toolkit/images/icons_large/twitter.png' ?>" alt="<?php the_author_meta('twitter', $curauth->ID); ?>" title="<?php the_author_meta('twitter', $curauth->ID); ?>" /></a></li>
<?php endif; ?>
<?php if(get_the_author_meta('facebook', $curauth->ID)): ?>
<li><a href="<?php the_author_meta('facebook', $curauth->ID); ?>"><img src="<?php echo plugins_url() . '/social-sharing-toolkit/images/icons_large/facebook.png' ?>" alt="<?php the_author_meta('facebook', $curauth->ID); ?>" title="<?php the_author_meta('facebook', $curauth->ID); ?>" /></a></li>
<?php endif; ?>
<?php if(get_the_author_meta('linkedin', $curauth->ID)): ?>
<li><a href="<?php the_author_meta('linkedin', $curauth->ID); ?>"><img src="<?php echo plugins_url() . '/social-sharing-toolkit/images/icons_large/linkedin.png' ?>" alt="<?php the_author_meta('linkedin', $curauth->ID); ?>" title="<?php the_author_meta('linkedin', $curauth->ID); ?>" /></a></li>
<?php endif; ?>
<?php if(get_the_author_meta('googleplus', $curauth->ID)): ?>
<li><a href="<?php the_author_meta('googleplus', $curauth->ID); ?>"><img src="<?php echo plugins_url() . '/social-sharing-toolkit/images/icons_large/googleplus.png' ?>" alt="<?php the_author_meta('googleplus', $curauth->ID); ?>" title="<?php the_author_meta('googleplus', $curauth->ID); ?>" /></a></li>
<?php endif; ?>
<?php if(get_the_author_meta('flickr', $curauth->ID)): ?>
<li><a href="<?php the_author_meta('flickr', $curauth->ID); ?>"><img src="<?php echo plugins_url() . '/social-sharing-toolkit/images/icons_large/flickr.png' ?>" alt="<?php the_author_meta('flickr', $curauth->ID); ?>" title="<?php the_author_meta('flickr', $curauth->ID); ?>" /></a></li>
<?php endif; ?>
<?php if(get_the_author_meta('picasa', $curauth->ID)): ?>
<li><a href="<?php the_author_meta('picasa', $curauth->ID); ?>"><img src="<?php echo plugins_url() . '/social-sharing-toolkit/images/icons_large/picasa.png' ?>" alt="<?php the_author_meta('picasa', $curauth->ID); ?>" title="<?php the_author_meta('picasa', $curauth->ID); ?>" /></a></li>
<?php endif; ?>
<?php if(get_the_author_meta('vimeo', $curauth->ID)): ?>
<li><a href="<?php the_author_meta('vimeo', $curauth->ID); ?>"><img src="<?php echo get_template_directory_uri() . '/img/vimeo.png'; ?>" alt="<?php the_author_meta('vimeo', $curauth->ID); ?>" title="<?php the_author_meta('vimeo', $curauth->ID); ?>" /></a></li>
<?php endif; ?>
<?php if(get_the_author_meta('youtube', $curauth->ID)): ?>
<li><a href="<?php the_author_meta('youtube', $curauth->ID); ?>"><img src="<?php echo plugins_url() . '/social-sharing-toolkit/images/icons_large/youtube.png' ?>" alt="<?php the_author_meta('youtube', $curauth->ID); ?>" title="<?php the_author_meta('youtube', $curauth->ID); ?>" /></a></li>
<?php endif; ?>
</ul>
</div><!-- .author-contact -->
</div><!-- .author-body -->
<?php // Display the next few fields only for Artists and Artist Members
$role = get_user_meta( $curauth->ID, 'wpaw_capabilities' );
if ( in_array( array('artist' => '1'), $role ) || in_array( array('artist_member' => '1'), $role ) ) { ?>
<hr />
<h2 class="author-sub">Artist Statement</h2>
<div class="author-graf"><?php echo get_user_meta( $curauth->ID, 'artist_statement', true ); ?></div>
<hr />
<h2 class="author-sub">Educational Background</h2>
<div class="author-graf"><?php echo get_user_meta( $curauth->ID, 'educational_background', true ); ?></div>
<?php } // End if statement ?>
<?php // Display the next field only for Teaching Artists
$terms = wp_get_object_terms( $curauth->ID, 'teaching_artist' );
if ( !empty($terms) ) { ?>
<hr />
<h2 class="author-sub">Teaching Artist Experience</h2>
<div class="author-graf"><?php echo get_user_meta( $curauth->ID, 'teaching_artist_experience', true ); ?></div>
<?php } // End if statement ?>
<?php // Display Events only for Artist Members and Cultural Organizations
$role = get_user_meta( $curauth->ID, 'wpaw_capabilities' );
if ( in_array( array('artist_member' => '1'), $role ) || in_array( array('culturalorg' => '1'), $role ) || in_array( array('affiliate' => '1'), $role) ) { ?>
<hr />
<h2 class="author-sub">Events</h2>
<div id="profile-events-carousel" class="owl-carousel">
<?php if (class_exists('EM_Events')) {
$args = array(
'limit' => 5,
'owner' => $curauth->ID,
'format' => '
<div id="profile-event">
{has_image}<div class="event-img">#_EVENTIMAGECUSTOM</div>{/has_image}
<h3>#_EVENTLINK</h3>
<p>#_EVENTDATES<br /><em>#_EVENTTIMES</em></p>
{has_blurb}<p>#_ATT{Blurb}</p>{/has_blurb}
</div>
'
);
echo EM_Events::output($args); } ?>
</div>
<hr />
<h2 class="author-sub">Classes, Workshops</h2>
<div id="profile-classes-carousel" class="owl-carousel">
<?php if (class_exists('EM_Events')) {
$args = array(
'limit' => 5,
'owner' => $curauth->ID,
'category' => array(32, 26),
'format' => '
<div id="profile-event">
{has_image}<div class="event-img">#_EVENTIMAGECUSTOM</div>{/has_image}
<h3>#_EVENTLINK</h3>
<p>#_EVENTDATES<br /><em>#_EVENTTIMES</em></p>
{has_blurb}<p>#_ATT{Blurb}</p>{/has_blurb}
</div>
'
);
echo EM_Events::output($args); } ?>
</div>
<hr />
<h2 class="author-sub">Blog</h2>
<div class="author-graf">
<?php $blog_query = new WP_Query(array('author' => $curauth->ID, 'cat' => 1, 'posts_per_page' => 1));
if ( $blog_query->have_posts() ) : while ( $blog_query->have_posts() ) : $blog_query->the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_post_thumbnail( 'thumbnail', array('class' => 'alignleft', 'alt' => trim(strip_tags( $wp_postmeta->_wp_attachment_image_alt ))) ); ?></a><?php } ?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_time('d M Y'); ?>
<?php the_excerpt(); ?>
<!-- <p class="readmore"><?php next_posts_link( '&raquo;Read more'); ?></p> -->
<?php endwhile; else: ?>
<p><?php _e('No blog posts written yet.'); ?></p>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>
<?php } // End if statement ?>
<?php // Display the next field only for Cultural Organizations
$role = get_user_meta( $curauth->ID, 'wpaw_capabilities' );
if ( in_array( array('culturalorg' => '1'), $role ) || in_array( array('affiliate' => '1'), $role ) ) { ?>
<!-- <hr />
<h2 class="author-sub">Arts Deals</h2>
<div class="author-graf"></div> -->
<hr />
<h2 class="author-sub">Press</h2>
<div class="author-graf">
<?php $press_query = new WP_Query(array('author' => $curauth->ID, 'cat' => 11, 'posts_per_page' => 3));
if ( $press_query->have_posts() ) : while ( $press_query->have_posts() ) : $press_query->the_post(); ?>
<h3 id="author-press">Headline: <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php endwhile; else: ?>
<p><?php _e('No press releases written yet.'); ?></p>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>
<?php } // End Cultural Org-only section ?>
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
<?php get_footer(); ?>
<?php
/**
* Template for Artists Directory page.
*
*
* @package ArtsWestchester
* @since ArtsWestchester 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
// Start the loop here
if ( have_posts() ) :
while ( have_posts() ) : the_post();
// Display content of page ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
<hr />
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php edit_post_link( __( 'Edit', 'arts_west' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-content -->
</article>
<?php
// Reset post data and end (page) loop
// wp_reset_postdata();
// End the loop for page content
endwhile;
endif; ?>
<?php
// Return a list of terms in Artist taxonomy
$args = array( 'hide_empty' => 'false' );
$terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'artist', 'term_args' => $args) );
$count = count($terms); $i=0;
if ($count > 0) {
echo '<ul class="custom-tax-list">';
foreach ($terms as $term) {
$i++;
$term_list .= '<li><a href="/artists/directory/' . $term->slug . '" title="' . sprintf(__('View all profiles under %s', 'arts_west'), $term->name) . '">' . wp_get_attachment_image( $term->image_id, 'full' ) . '<br />' . $term->name . '</a></li>';
}
echo $term_list;
echo '</ul>';
} ?>
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
/**
* Template for Cultural Organizations Directory page.
*
*
* @package ArtsWestchester
* @since ArtsWestchester 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
// Start the loop here
if ( have_posts() ) :
while ( have_posts() ) : the_post();
// Display content of page ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
<hr />
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php edit_post_link( __( 'Edit', 'arts_west' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-content -->
</article>
<?php
// Reset post data and end (page) loop
// wp_reset_postdata();
// End the loop for page content
endwhile;
endif; ?>
<?php
// Return a list of terms in Cultural Organization taxonomy
$args = array( 'hide_empty' => 'false' );
$terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'culturalorg', 'term_args' => $args) );
$count = count($terms); $i=0;
if ($count > 0) {
echo '<ul class="custom-tax-list">';
foreach ($terms as $term) {
$i++;
$term_list .= '<li><a href="/cultural-organizations/directory/' . $term->slug . '" title="' . sprintf(__('View all profiles under %s', 'arts_west'), $term->name) . '">' . wp_get_attachment_image( $term->image_id, 'full' ) . '<br />' . $term->name . '</a></li>';
}
echo $term_list;
echo '</ul>';
} ?>
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
/**
* The template for term archive: Artists.
*
* This displays the Artists Directory pages, listing Artists under a Category archive (e.g. "Artists: Literary").
*
* @package ArtsWestchester
* @since ArtsWestchester 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<a href="<?php echo esc_url( home_url( '/artists/directory/' ) ); ?>" class="directory-crumb">&laquo;Back to directory</a><br />
<?php $args = array( 'taxonomy' => 'artist' );
$terms = get_terms('artist', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$term_list = '<p class="list-term-archive">Categories: ';
foreach ($terms as $term) {
$i++;
$term_list .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf(__('View all Artists filed under %s', 'arts_west'), $term->name) . '">' . $term->name . '</a>';
if ($count != $i) $term_list .= ' <span class="sep">-</span> '; else $term_list .= '</p>';
}
echo $term_list;
} ?>
<header class="page-header">
<h1 class="entry-title"><?php printf( __( 'Artists: %s', 'arts_west' ), '' . single_cat_title( '', false ) . '' ); ?></h1>
</header>
<div class="entry-content">
<ul class="profile-cats-list">
<?php
$term_id = get_queried_object_id();
//print_r($term_id);
$term = get_queried_object();
//$args = array( 'order' => 'DESC', 'objects_per_page' => 5 );
//$users = get_objects_in_term( $term_id, $term->taxonomy, $args );
$users = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM wpaw_artist where tid = '%d'",$term_id)
);
$usercount = $wpdb->get_results(
$wpdb->prepare(
"count ID FROM wpaw_artist where tid = '%d'",$term_id)
);
//print_r($usercount);
if ( !empty( $users ) ) {
?>
<?php
foreach($wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM wpaw_artist where tid = '%d' order by display_name ASC;",$term_id)
) as $key=>$row) {
$user_id = $row->ID;
$tid = $row->tid;
$tname = $row->term;
$nice_name = $row->nice_name;
$display_name = $row->display_name;
$email = $row->email;
$role = $row->role;
$taxonomy = $row->taxonomy;
//print_r($user_id);
?>
<li class="profile-cat">
<?php $profile_image = get_user_meta( $user_id, 'default_profile_image' );
if ( $profile_image ) {
foreach ( $profile_image as $attachment_id ) {
$link = get_author_posts_url( $user_id );
$medium = wp_get_attachment_image( $attachment_id, 'medium', 0, array('class'=>'alignleft') );
printf( '<a class="img" href="%s">%s</a>', $link, $medium );
}
} ?>
<h2 class="profile-directory"><a href="<?php echo esc_url( get_author_posts_url( $user_id ) ); ?>"><?php the_author_meta( 'display_name', $user_id ); ?></a></h2>
<?php
$author_terms = wp_get_object_terms( $user_id, 'artist' );
if(!empty($author_terms)){
if(!is_wp_error( $author_terms )){
echo '<h3 class="profile-directory">Category: ';
foreach ($author_terms as $author_term) {
echo '<a href="'.get_term_link($author_term->slug, 'artist').'">'.$author_term->name.'</a><span class="sep">, </span>';
}
echo '</h3>';
}
}
$trim_length = 250; //desired length of text to display
$custom_field = 'artist_statement';
$value = get_user_meta($user_id, $custom_field, true);
$string = preg_replace('/\s+?(\S+)?$/', '', substr($value, 0, $trim_length));
if ($value) {
echo '<p>' . $string . '...</p>';
}
?>
<p><a class="directory-crumb" href="<?php echo esc_url( get_author_posts_url( $user_id ) ); ?>">View profile&raquo;</a></p>
</li>
<?php } ?>
<?php arts_west_content_nav( 'nav-below' ); ?>
<?php } ?>
</ul>
</div><!-- #entry-content -->
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
/**
* The template for term archive: Cultural Organizations.
*
* This displays the Cultural Organizations Directory pages, listing Cultural Organizations under a Category archive (e.g. "Cultural Organizations: Galleries").
*
* @package ArtsWestchester
* @since ArtsWestchester 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<a href="<?php echo esc_url( home_url( '/directory/' ) ); ?>" class="directory-crumb">&laquo;Back to directory</a><br />
<?php $args = array( 'taxonomy' => 'culturalorg' );
$terms = get_terms('culturalorg', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$term_list = '<p class="list-term-archive">Categories: ';
foreach ($terms as $term) {
$i++;
$term_list .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf(__('View all Organizations filed under %s', 'arts_west'), $term->name) . '">' . $term->name . '</a>';
if ($count != $i) $term_list .= ' <span class="sep">-</span> '; else $term_list .= '</p>';
}
echo $term_list;
} ?>
<header class="page-header">
<h1 class="entry-title"><?php printf( __( 'Cultural Organizations: %s', 'arts_west' ), '' . single_cat_title( '', false ) . '' ); ?></h1>
</header>
<div class="entry-content">
<ul class="profile-cats-list">
<?php
$term_id = get_queried_object_id();
//print_r($term_id);
$term = get_queried_object();
//print_r($term);
//
$users = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM wpaw_cultorg where tid = '%d'",$term_id)
);
//print_r($users);
if ( !empty( $users ) ) {
?>
<?php
foreach($wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM wpaw_cultorg where tid = '%d' order by display_name ASC;",$term_id)
) as $key=>$row) {
$user_id = $row->ID;
$tid = $row->tid;
$tname = $row->term;
$nice_name = $row->nice_name;
$display_name = $row->display_name;
$email = $row->email;
$role = $row->role;
$taxonomy = $row->taxonomy;
//print_r($user_id);
//echo "\r\n";
//print_r($tid);
//echo "\r\n";
//print_r($nice_name);
//echo "\r\n";
//print_r($display_name);
//echo "\r\n";
//print_r($email);
//echo "\r\n";
//print_r($role);
//echo "\r\n";
//print_r($taxonomy);
//echo "\r\n";
//print_r($tname);
//echo "\r\n";
?>
<li class="profile-cat">
<?php $profile_image = get_user_meta( $user_id, 'default_profile_image' );
if ( $profile_image ) {
foreach ( $profile_image as $attachment_id ) {
$link = get_author_posts_url( $user_id );
$medium = wp_get_attachment_image( $attachment_id, 'medium', 0, array('class'=>'alignleft') );
printf( '<a class="img" href="%s">%s</a>', $link, $medium );
}
} ?>
<h2 class="profile-directory"><a href="<?php echo esc_url( get_author_posts_url( $user_id ) ); ?>"><?php the_author_meta( 'display_name', $user_id ); ?></a></h2>
<?php
$org_terms = wp_get_object_terms( $user_id, 'culturalorg' );
if(!empty($org_terms)){
if(!is_wp_error( $org_terms )){
echo '<h3 class="profile-directory">Category: ';
foreach ($org_terms as $org_term) {
echo '<a href="'.get_term_link($org_term->slug, 'culturalorg').'">'.$org_term->name.'</a><span class="sep">, </span>';
}
echo '</h3>';
}
}
$trim_length = 250; //desired length of text to display
$custom_field = 'mission';
$value = get_user_meta($user_id, $custom_field, true);
if ($value) {
echo '<p>' . rtrim(substr($value,0,$trim_length)) . '...</p>';
}
?>
<p><a class="directory-crumb" href="<?php echo esc_url( get_author_posts_url( $user_id ) ); ?>">View profile&raquo;</a></p>
</li>
<?php } ?>
<?php } ?>
</ul>
</div><!-- #entry-content -->
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
/**
* Plugin Name: Arts Westchester User Taxonomies and Custom Post Types
* Plugin URI: http://tadpole.cc
* Author: Tadpole Collective LLC
* Author URI: http://tadpole.cc
* Description: Adds Artist, Teaching Artist and Cultural Orginzation (user) taxonomies. Creates Artist Opportunities custom post type with its own custom taxonomy. Also modifies default 'author' slug.
* Version: 0.5.1
* License: GPLv2
*
*
* This is heavily inspired by previous work by Justin Tadlock
* http://justintadlock.com/archives/2011/10/20/custom-user-taxonomies-in-wordpress
*
* Contributions by Damian Gostomski
* http://gostomski.co.uk/code/wordpress-user-taxonomies
*
* Tadpole Collective gratefully acknowledges the work of the above developers for inspiration and guidance in this plugin.
*
*/
/**
* Remove author slug, replace with 'profile', e.g. https://artswestchester.org/profile/demoartist/
*
*/
function tc_author_base() {
global $wp_rewrite;
$wp_rewrite->author_base = 'profile';
}
add_action('init', 'tc_author_base');
/**
* Registers the 'artist' taxonomy for users. This is a taxonomy for the 'user' object type rather than a
* post being the object type.
*/
add_action( 'init', 'tc_register_artist_taxonomy', 0 );
function tc_register_artist_taxonomy() {
register_taxonomy(
'artist',
'user',
array(
'public' => true,
'hierarchical' => true,
'labels' => array(
'name' => __( 'Artist Categories' ),
'singular_name' => __( 'Artist Category' ),
'menu_name' => __( 'Artists Categories' ),
'search_items' => __( 'Search Artist Categories' ),
'popular_items' => __( 'Popular Artist Categories' ),
'all_items' => __( 'All Artist Categories' ),
'edit_item' => __( 'Edit Artist Category' ),
'update_item' => __( 'Update Artist Category' ),
'add_new_item' => __( 'Add New Artist Category' ),
'new_item_name' => __( 'New Artist Category Name' ),
'separate_items_with_commas' => __( 'Separate Artist Categories with commas' ),
'add_or_remove_items' => __( 'Add or remove Artist Category' ),
'choose_from_most_used' => __( 'Choose from the most popular Artist Categories' ),
),
'rewrite' => array(
'with_front' => true,
'slug' => 'artists/directory' // Careful with slugs :^)
),
'capabilities' => array(
'manage_terms' => 'edit_artist', // Using 'edit_users' cap to keep this simple.
'edit_terms' => 'edit_artist',
'delete_terms' => 'edit_artist',
'assign_terms' => 'assign_artist',
),
)
);
}
/**
* Registers the 'teaching artist' taxonomy for users. This is a taxonomy for the 'user' object type rather than a
* post being the object type. Only admins can add these (designed to be one term).
*/
add_action( 'init', 'tc_register_teachingartist_taxonomy', 0 );
function tc_register_teachingartist_taxonomy() {
register_taxonomy(
'teaching_artist',
'user',
array(
'public' => true,
'hierarchical' => true,
'labels' => array(
'name' => __( 'Teaching Artist Categories' ),
'singular_name' => __( 'Teaching Artist Category' ),
'menu_name' => __( 'Teaching Artist Categories' ),
'search_items' => __( 'Search Teaching Artist Categories' ),
'popular_items' => __( 'Popular Teaching Artist Categories' ),
'all_items' => __( 'All Teaching Artist Categories' ),
'edit_item' => __( 'Edit Teaching Artist Category' ),
'update_item' => __( 'Update Teaching Artist Category' ),
'add_new_item' => __( 'Add New Teaching Artist Category' ),
'new_item_name' => __( 'New Teaching Artist Category Name' ),
'separate_items_with_commas' => __( 'Separate Teaching Artists Categories with commas' ),
'add_or_remove_items' => __( 'Add or remove Teaching Artist Category' ),
'choose_from_most_used' => __( 'Choose from the most popular Teaching Artist Categories' ),
),
'capabilities' => array(
'manage_terms' => 'edit_tartist', // Using 'edit_users' cap to keep this simple.
'edit_terms' => 'edit_tartist',
'delete_terms' => 'edit_tartist',
'assign_terms' => 'manage_tartist',
),
)
);
}
/**
* Registers the 'culturalorg' taxonomy for users. This is a taxonomy for the 'user' object type rather than a
* post being the object type.
*/
add_action( 'init', 'tc_register_culturalorg_taxonomy', 0 );
function tc_register_culturalorg_taxonomy() {
register_taxonomy(
'culturalorg',
'user',
array(
'public' => true,
'hierarchical' => true,
'labels' => array(
'name' => __( 'Cultural Organization Categories' ),
'singular_name' => __( 'Cultural Organization Category' ),
'menu_name' => __( 'Cultural Organization Categories' ),
'search_items' => __( 'Search Cultural Organization Categories' ),
'popular_items' => __( 'Popular Cultural Organization Categories' ),
'all_items' => __( 'All Cultural Organization Categories' ),
'edit_item' => __( 'Edit Cultural Organization Categories' ),
'update_item' => __( 'Update Cultural Organization Category' ),
'add_new_item' => __( 'Add New Cultural Organization Category' ),
'new_item_name' => __( 'New Cultural Organization Category Name' ),
'separate_items_with_commas' => __( 'Separate Cultural Organization Categories with commas' ),
'add_or_remove_items' => __( 'Add or remove Cultural Organization Categories' ),
'choose_from_most_used' => __( 'Choose from the most popular Cultural Organization Categories' ),
),
'rewrite' => array(
'with_front' => true,
'slug' => 'cultural-organizations/directory' // Careful with slugs :^)
),
'capabilities' => array(
'manage_terms' => 'edit_culturalorg', // Using 'edit_users' cap to keep this simple.
'edit_terms' => 'edit_culturalorg',
'delete_terms' => 'edit_culturalorg',
'assign_terms' => 'assign_culturalorg',
),
)
);
}
class DJG_UserTaxonomies {
private static $taxonomies = array();
/**
* Register all the hooks and filters we can in advance
* Some will need to be registered later on, as they require knowledge of the taxonomy name
*/
public function __construct() {
// Taxonomies
add_action('registered_taxonomy', array($this, 'registered_taxonomy'), 10, 3);
// Menus
add_action('admin_menu', array($this, 'admin_menu'));
add_filter('parent_file', array($this, 'parent_menu'));
// User Profiles
add_action('show_user_profile', array($this, 'user_profile'));
add_action('edit_user_profile', array($this, 'user_profile'));
add_action('personal_options_update', array($this, 'save_profile'));
add_action('edit_user_profile_update', array($this, 'save_profile'));
add_filter('sanitize_user', array($this, 'restrict_username'));
}
/**
* This is our way into manipulating registered taxonomies
* It's fired at the end of the register_taxonomy function
*
* @param String $taxonomy - The name of the taxonomy being registered
* @param String $object - The object type the taxonomy is for; We only care if this is "user"
* @param Array $args - The user supplied + default arguments for registering the taxonomy
*/
public function registered_taxonomy($taxonomy, $object, $args) {
global $wp_taxonomies;
// Only modify user taxonomies, everything else can stay as is
if($object != 'user') return;
// We're given an array, but expected to work with an object later on
$args = (object) $args;
// Register any hooks/filters that rely on knowing the taxonomy now
add_filter("manage_edit-{$taxonomy}_columns", array($this, 'set_user_column'));
add_action("manage_{$taxonomy}_custom_column", array($this, 'set_user_column_values'), 10, 3);
// Set the callback to update the count if not already set
if(empty($args->update_count_callback)) {
$args->update_count_callback = array($this, 'update_count');
}
// We're finished, make sure we save out changes
$wp_taxonomies[$taxonomy] = $args;
self::$taxonomies[$taxonomy] = $args;
}
/**
* We need to manually update the number of users for a taxonomy term
*
* @see _update_post_term_count()
* @param Array $terms - List of Term taxonomy IDs
* @param Object $taxonomy - Current taxonomy object of terms
*/
public function update_count($terms, $taxonomy) {
global $wpdb;
foreach((array) $terms as $term) {
$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term));
do_action('edit_term_taxonomy', $term, $taxonomy);
$wpdb->update($wpdb->term_taxonomy, compact('count'), array('term_taxonomy_id'=>$term));
do_action('edited_term_taxonomy', $term, $taxonomy);
}
}
/**
* Add each of the taxonomies to the Users menu
* They will behave in the same was as post taxonomies under the Posts menu item
* Taxonomies will appear in alphabetical order
*/
public function admin_menu() {
// Put the taxonomies in alphabetical order
$taxonomies = self::$taxonomies;
ksort($taxonomies);
foreach($taxonomies as $key=>$taxonomy) {
add_users_page(
$taxonomy->labels->menu_name,
$taxonomy->labels->menu_name,
$taxonomy->cap->manage_terms,
"edit-tags.php?taxonomy={$key}"
);
}
}
/**
* Fix a bug with highlighting the parent menu item
* By default, when on the edit taxonomy page for a user taxonomy, the Posts tab is highlighted
* This will correct that bug
*/
function parent_menu($parent = '') {
global $pagenow;
// If we're editing one of the user taxonomies
// We must be within the users menu, so highlight that
if(!empty($_GET['taxonomy']) && $pagenow == 'edit-tags.php' && isset(self::$taxonomies[$_GET['taxonomy']])) {
$parent = 'users.php';
}
return $parent;
}
/**
* Correct the column names for user taxonomies
* Need to replace "Posts" with "Users"
*/
public function set_user_column($columns) {
unset($columns['posts']);
$columns['users'] = __('Users');
return $columns;
}
/**
* Set values for custom columns in user taxonomies
*/
public function set_user_column_values($display, $column, $term_id) {
if('users' === $column) {
$term = get_term($term_id, $_GET['taxonomy']);
echo $term->count;
}
}
/**
* Add the taxonomies to the user view/edit screen
*
* @param Object $user - The user of the view/edit screen
*/
public function user_profile($user) {
// Using output buffering as we need to make sure we have something before outputting the header
// But we can't rely on the number of taxonomies, as capabilities may vary
ob_start();
foreach(self::$taxonomies as $key=>$taxonomy):
// Check the current user can assign terms for this taxonomy
if(!current_user_can($taxonomy->cap->assign_terms)) continue;
// Get all the terms in this taxonomy
$terms = get_terms($key, array('hide_empty'=>false,'parent'=>'0'));
?>
<table class="form-table">
<tr>
<th><label for=""><?php _e("Select {$taxonomy->labels->singular_name}")?></label></th>
<td>
<?php if(!empty($terms)):?>
<?php foreach($terms as $term):?>
<?php $termchildren = get_term_children( $term->term_id,$term->taxonomy ); ?>
<label for="<?php echo "{$key}-{$term->slug}"?>">
<input type="checkbox" name="<?php echo $key?>[]" id="<?php echo "{$key}-{$term->slug}"?>" value="<?php echo $term->slug?>" <?php checked(true, is_object_in_term($user->ID, $key, $term->term_id))?> />
<?php echo $term->name?></label>
<?php foreach ( $termchildren as $child ):?>
<?php $tchild = get_term_by('id',$child,$term->taxonomy);?>
<label for="<?php echo "{$key}-{$tchild->slug}"?>">
<input type="checkbox" style="margin-left: 15px;" name="<?php echo $key?>[]" id="<?php echo "{$key}-{$tchild->slug}"?>" value="<?php echo $tchild->slug?>" <?php checked(true, is_object_in_term($user->ID, $key, $tchild->term_id))?> />
<?php echo $tchild->name?></label>
<?php endforeach; // Children ?>
<?php endforeach; // Terms?>
<?php else:?>
<?php _e("There are no {$taxonomy->labels->name} available.")?>
<?php endif?>
</td>
</tr>
</table>
<?php
endforeach; // Taxonomies
// Output the above if we have anything, with a heading
$output = ob_get_clean();
if(!empty($output)) {
echo '<h3>', __('Directory Categories'), '</h3>';
echo $output;
}
}
/**
* Save the custom user taxonomies when saving a users profile
*
* @param Integer $user_id - The ID of the user to update
*/
public function save_profile($user_id) {
foreach(self::$taxonomies as $key => $taxonomy) {
// Check the current user can edit this user and assign terms for this taxonomy
if(!current_user_can('edit_user', $user_id) && current_user_can($taxonomy->cap->assign_terms)) return false;
// Save the data
$user_terms = ! is_array($_POST[$key]) ? array($_POST[$key]) : $_POST[$key];
wp_set_object_terms($user_id, $user_terms, $key, false);
clean_object_term_cache($user_id, $key);
}
}
/**
* Usernames can't match any of our user taxonomies
* As otherwise it will cause a URL conflict
* This method prevents that happening
*/
public function restrict_username($username) {
if(isset(self::$taxonomies[$username])) return '';
return $username;
}
}
new DJG_UserTaxonomies;
@robertandrews
Copy link

Confused by this. Can't get to seem this plugin working - but the Plugin shows an update available - not for your version but for the Damian Gostomski version, which you said was old. When I update in the Dashboard to that, my taxonomy seems to work.
Huh?

One extra thing - even though it seems to work, it's a shame not to have the add-term option in the taxonomy box on the Edit User page.

@kmeronuk
Copy link

Question about this. Your user-taxonomies.php file don't reference setting up custom db tables for this, but looking at both taxonomy-culturalorg.php and taxonomy-artist.php where you query the db directly, it looks like you are in fact querying custom tables (wpaw_artist and wpaw_cultorg).

Any chance you have updated versions of any of the files or code you'd be willing to share that shows how you've set this up and are using it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment