Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.