Skip to content

Instantly share code, notes, and snippets.

@robbm76
Last active April 19, 2016 14:55
Show Gist options
  • Save robbm76/d2b080c7c5f1a36a2246edbd71d0ee73 to your computer and use it in GitHub Desktop.
Save robbm76/d2b080c7c5f1a36a2246edbd71d0ee73 to your computer and use it in GitHub Desktop.
/* Degree List
----------------------------------*/
// CPT Slug = 'degree'
// TAX Slug = 'school'
add_shortcode( 'degree_list', 'mbu_degree_list_shortcode' );
function mbu_degree_list_shortcode ( $atts, $content = null ) {
extract( shortcode_atts( array(
'school' => ''
),
$atts, 'degree_list' ) );
ob_start();
$args = array(
'post_type' => 'degree',
'posts_per_page' => 100,
'tax_query' => array(
array(
'taxonomy' => 'school',
'field' => 'slug',
'terms' => $school
)
)
);
$degrees = new WP_Query( $args );
if ( $degrees->have_posts() ) {
while ( $degrees->have_posts() ) {
$degrees->the_post(); ?>
<a href="<?php the_permalink(); ?>"><h5><?php the_title(); ?></a></h5>
<?php
}
}
wp_reset_postdata();
echo '<div style="clear:both;"></div>';
$myvariable = ob_get_clean();
return $myvariable;
echo '<div style="clear:both;"></div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment