WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a simple plugin to insert some post links in a post at the right place.

The query part works okay in a template, but my attempt at a displaying via plugin just returns a blank space.

//tell wordpress to register the wafunitslist shortcode
add_shortcode("waf-units-list", "wafunitslist_handler");

function wafunitslist_handler() {

function wafunitslist_function() {
<?php $country = get_post_meta(get_the_ID(), "Country", true); ?>
<?php $operator = get_post_meta(get_the_ID(), "Operator", true); ?>

<?php query_posts('cat=738&meta_key=Operator&meta_value='.$operator.'&orderby=title&posts_per_page=-1&order=ASC' ); ?>

   // Reset and setup variables
   $output = '';
   $temp_title = '';
   $temp_link = '';

   // the loop
   if (have_posts()) : while (have_posts()) : the_post();

      $temp_title = get_the_title($post->ID);
      $temp_link = get_permalink($post->ID);

      // output all findings - CUSTOMIZE TO YOUR LIKING
      $output .= '<li><a href="'.$temp_link.'">'.$temp_title.'</a></li>';

   endwhile; else:

      $output .= 'nothing found';


   return $output;


Replacing 'return' by 'echo' shows a list of links at the top of the post, but 'return' gives nothing. What am I doing wrong? This is driving me a bit crazy.

Thanks for any help.

share|improve this question

closed as too localized by kaiser, toscho Oct 4 '12 at 0:11

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

You're missing a 'return' from your shortcode handler:

function wafunitslist_handler() {
    return wafunitslist_function();
share|improve this answer

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