I have this plugin that displays category featured image thumbnails for each post via shortcodes.. like so,

[categorythumbnaillist 3] (3 being the category of course)

I would like it to only show posts with the tag "news".. only if you set the tag value to "news" via the shortcode. So if you entered in...

[categorythumbnaillist 3 tag="news"]

Then it should only show posts with the news tag in it. If no tag is entered, it should then display the posts for the respective category like the plugin already does.

Here is the code I made for displaying the results.

      'showposts'=> 5,
      'category'=> $listCatId[1],
      'orderby'=> $categoryThumbnailList_OrderType,
      'order'=> $categoryThumbnailList_Order

$myposts = get_posts( $args);
$output = '<div class="categoryThumbnailList">';
foreach($myposts as $post) :

I tried to read and understand Wordpress's shortcode API, but I just couldn't seem to wrap my head around it.

There are more functions from the plugin, So I have provided the full plugin code here: http://pastebin.com/QHrB8xUn

Any help to getting my plugin shortcode to filter results by the tag news (if entered) would truely be appreciated. :)

  • Have a look at the shortcode_atts() function
    – shea
    Dec 3 '12 at 20:07
  • I've been looking at the link you provided trying to implement attributes into my plugin, but nothing seems to be working. My plugin doesn't even use the "add_shortcode" line, and it's real hard to figure out where to put the code to filter out thumbnails by tag.. let alone how to do it at all. :( With that being said, your link did somewhat put me in the right direction. But it will probably take me weeks figuring out how to only show posts with the tag "news".. only if you set the tag value to "news" via the shortcode. And where to put it in my actual plugin. Thanks for the help tho Shea Dec 3 '12 at 20:55

That plugin you have is not using the WordPress Shortcode API as it should be. There is not a single add_shortcode to be found. It has basically cooked up its own shortcode 'feature' by hooking a preg_replace_calback into the_content

define("categoryThumbnailList_REGEXP", "/\[categorythumbnaillist ([[:print:]]+)\]/");

define("categoryThumbnailList_TARGET", "###CATTHMBLST###");

function categoryThumbnailList_callback($listCatId) {


function categoryThumbnailList($content) {
        return (preg_replace_callback(categoryThumbnailList_REGEXP, 'categoryThumbnailList_callback', $content));


add_filter('the_content', 'categoryThumbnailList',1);

That is not really the way to do this. The normal shortcode functions aren't going to work correctly.

The callback function, categoryThumbnailList_callback, is only expecting an ID value, $listCatId, so what you are doing is going to take rewrite. You might be able to hack it by parsing that $listCatId value to extract your extra information-- try var_dump($listCatId); at the top of that function and see if you have anything usable. I'd have to install and run this to be able to write good code, but my recommendation is to rewrite the plugin to use the API correctly.

That plugin is listed as being for "WordPress 2.9 and up" so maybe it is just an old plugin, which would be another reason to rewrite.

  • Thanks a lot. I ended up using a new plugin with shortcodes that did what I want. It's taking a long time for me to modify it... but it's deff. worth it. Thanks for the suggestion. :) Dec 3 '12 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.