Skip to content

Instantly share code, notes, and snippets.

@alexkingorg
Created July 13, 2013 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkingorg/5991434 to your computer and use it in GitHub Desktop.
Save alexkingorg/5991434 to your computer and use it in GitHub Desktop.
Shortcode to output projects by group.
<?php
function akv3_project_group_shortcode($atts) {
extract(shortcode_atts(array(
'group' => null,
'description' => null,
), $atts));
if (empty($group)) {
return '';
}
$term = get_term_by('slug', $group, 'project-groups');
?>
<h2 class="widget-title clearfix"><?php echo esc_html($term->name); ?></h2>
<div class="project-group clearfix">
<?php
if (!empty($description)) {
echo wpautop(wptexturize($description));
}
$args = array(
'post_type' => 'project',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'project-groups',
'field' => 'slug',
'terms' => $group,
)
)
);
if ($group != 'featured') {
$args['tax_query'][] = array(
'taxonomy' => 'project-groups',
'field' => 'slug',
'terms' => 'featured',
'operator' => 'NOT IN'
);
}
$query = new WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
// AKV#_PATH is defined in my child theme
include(AKV3_PATH.'misc/project-summary.php');
}
?>
</div>
<?php
wp_reset_postdata();
}
add_shortcode('project-group', 'akv3_project_group_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment