This is my 2nd question about shortcode as I'm learning shortcode.
Here is my code:
add_shortcode('work-shortcode', 'work_shortcode');
function work_shortcode()
{
$return_string .= '<div class="work">';
$return_string .= '<div class="container">';
$return_string .= '<div class="portfolio-wrapper">';
$return_string .= '<ul class="filter text-center wow fadeInUp" data-wow-delay="300ms">';
$return_string .= '<li>';
$return_string .= '<a class="selected" href="#" data-filter="*">All';
$return_string .= '</a>';
$return_string .= '</li>';
$terms = get_terms("filter"); // get all categories, but you can use any taxonomy
$count = count($terms); //How many are they?
if ( $count > 0 ){ //If there are more than 0 terms
foreach ( $terms as $term ) { //for each term:
$return_string .= '<li>';
$return_string .= '<a href="#" data-filter="'.$term->slug.'">';
$return_string .= $term->name;
$return_string .= '</a>';
$return_string .= '</li>';
//create a list item with the current term slug for sorting, and name for label
}
}
$return_string .= '</ul>';
$our_work = new WP_Query(array(
'post_type' => 'our_work',
'posts_per_page' =>50,
)); //Check the WP_Query docs to see how you can limit which posts to display
if ( $our_work->have_posts() ) :
$return_string .= '<ul class="portfolio-items">';
while ( $our_work->have_posts() ) : $our_work->the_post();
$termsArray = get_the_terms( $post->ID, "filter" ); //Get the terms for this particular item
$termsString = ""; //initialize the string that will contain the terms
foreach ( $termsArray as $term ) { // for each term
$termsString .= $term->slug.' '; //create a string that has all the slugs
}
$return_string .= '<li class="'.$termsString. 'item">';
$return_string .= '<div class="infos">';
$return_string .= '<div class="img-responsive">';
$return_string .= get_the_post_thumbnail();
$return_string .= '</div>';
$return_string .= '<div class="overlay">';
$return_string .= '<div class="text">';
$return_string .= '<h2>'.get_the_title().'</h2>';
$return_string .= '</div>';
$return_string .= '</div>';
$return_string .= '</div>';
$return_string .= '</li>';
endwhile;
wp_reset_postdata();
$return_string .= '</ul>';
$return_string .= '</div>';
$return_string .= '</div>';
endif;
return $return_string;
}
I'm having two problems actually:
1) My filters are not working(its working in page but not in shortcode). Here is code in page
<ul class="filter text-center wow fadeInUp" data-wow-delay="300ms">
<li>
<a class="selected" href="#" data-filter="*">All</a>
</li>
<?php
$terms = get_terms("filter"); // get all categories, but you can use any taxonomy
$count = count($terms); //How many are they?
if ( $count > 0 ){ //If there are more than 0 terms
foreach ( $terms as $term ) { //for each term:
echo "<li><a href='#' data-filter='.".$term->slug."'>" . $term->name . "
</a></li>\n";
//create a list item with the current term slug for sorting, and name for label
}
}
?>
</ul>
2) The shortcode not outputting the post thumbnail but when I put get_permalink() its outputting the links.. please help. Thankx..