Created
February 10, 2017 23:21
-
-
Save johngarcia9110/e4524e87d1ee6bf01f1cd517750b3513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function list_staff_members($atts, $content = null){ | |
//declare defaults and parse attributes | |
$atts = shortcode_atts(array( | |
'category' => 'Default Category' | |
), $atts); | |
} | |
$args = array( | |
'numberposts' => -1, | |
'post_type' => 'staff_members', //Custom post type slug | |
'tax_query' => array( | |
// Note: tax_query expects an array of arrays. | |
array( | |
'taxonomy' => 'staff_categories', // our custom post type taxonomy slug | |
'field' => 'slug', | |
'terms' => array($atts['category']), //our category shortcode attribute | |
), | |
), | |
); | |
$query = new WP_Query( $args ); | |
while ( $query->have_posts() ) : $query->the_post(); | |
//get post values | |
$title = get_field('staff_member_title'); //custom field in post | |
$postTitle = get_the_title(); | |
$postLink = get_permalink(); | |
//define html that we will return in our shortcode | |
$html = '<div class="staffMember">'; | |
$html .= '<img src="'. $postThumbLink .'">'; | |
$html .= '<h3>'.$postTitle.'</h3>'; | |
$html .= '<p>'. $title .'</p>'; | |
$html .= '<a class="btn-bio" href='. $postLink .'>Click To Read Bio</a>'; | |
$displayMember .= '</div>'; | |
endwhile; | |
wp_reset_query(); | |
//return our html | |
return $html; | |
add_shortcode('list_staff', 'list_staff_members'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment