Created
January 17, 2017 16:52
-
-
Save ingozoell/57642083edf84f077ece4fe5e9b2394d to your computer and use it in GitHub Desktop.
WordPress: Shortcode Loop with taxanomy
This file contains hidden or 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 sc_loop_highlights_lehrer() { | |
$args = array( 'post_type' => 'lehrer', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => array('publish'), | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'highlights', | |
'field' => 'slug', | |
'terms' => array('ja') | |
) | |
) | |
); | |
$string = ''; | |
$count = 0; | |
$query = new WP_Query( $args ); | |
if( $query->have_posts() ){ | |
$string .= '<div class="list-posts">'; | |
$string .= '<div class="lehrer-referenten-highlights wrap-cpt cf">'; | |
$string .= '<h2 class="heading-title">Highlights 2017</h2>'; | |
while( $query->have_posts() ){ | |
$query->the_post(); | |
$count++; | |
global $post; | |
$string .= '<div class="cpt nth-'. ($xyz++%2) .' ">'; | |
/* $string .= '<a class="block scroll " title="' . get_the_title() . '" href="' . esc_url( get_permalink(3970) ) .'#lehrer-referenten-id-' . get_the_ID() . '">'; */ | |
$string .= '<a class="block" title="' . get_the_title() . '" href="' . esc_url( get_permalink(3970) ) .'#' . $post->post_name . '">'; | |
$string .= '<div class="outer cf">'; | |
if( has_post_thumbnail() ) { | |
$string .= get_the_post_thumbnail( $post_id, 'partnerlogo' ); | |
} | |
$string .= '<div class="inner">'; | |
$string .= '<h4>'; | |
$string .= get_the_title(); | |
$string .= '</h4>'; | |
$string .= '</div>'; | |
$string .= '</div>'; | |
$string .= '</a>'; | |
$string .= '</div>'; | |
} | |
$string .= '</div></div>'; | |
} | |
wp_reset_postdata(); | |
return $string; | |
} | |
add_shortcode( 'highlights_lehrer', 'sc_loop_highlights_lehrer' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment