0

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..

4
  • Can you ask one question per question please? You're hurting your chances of getting a good answer by bundling them together Commented Mar 8, 2015 at 22:23
  • Hello Tom, Thanks for your suggestion. So should I ask another question for filters? Commented Mar 9, 2015 at 4:56
  • Yes! You can ask as many questions as you like :) All we ask is that they're on topic and well written, if a question is related to another you can always ask them in stages, or add links for previous context Commented Mar 9, 2015 at 15:46
  • Okay thanks Tom. But now I found the answer for the 1st question. Thankx again. I'll take care next time... :) Commented Mar 9, 2015 at 17:59

1 Answer 1

0
$return_string .= get_the_post_thumbnail();

should be:

$return_string .= get_the_post_thumbnail( get_the_ID() );
4
  • 2
    Can you explain how this answers the question? Commented Mar 8, 2015 at 22:23
  • Hi, Your answer worked.. should I accept it as correct answer because I didn't get the 2nd answer. thanks Commented Mar 9, 2015 at 4:54
  • Yes, That would be great! Commented Mar 9, 2015 at 22:41
  • @TomJNowell The code just needed get_the_ID(). Commented Mar 9, 2015 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.