Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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() {
    wafunitslist_function();
}

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' ); ?>

<?php
   // 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';

   endif;

   wp_reset_query();
   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.

add comment

1 Answer 1

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

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

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