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 have a shortcode [API-Module version="1"] and another shortcode like [API-Module version="2"]

If i handle any one at a time in a single page it works perfectly. Yet my requirement needs both had to be visible in front end(UI) when handling two shortcodes. Is there any possibilities to do so ?

Constructor to add short-code:

function __construct() {
            add_shortcode('API-Module', array(&$this, 'handle_shortcode'));
        }

This part is used in handling short-code:

 function handle_shortcode($atts) { 
 $version_type = $atts['version'];
    ob_start(); 
    require_once "/front_end/view/api-list.php"; 
    $output_string=ob_get_contents(); 
    ob_end_clean(); 
    return $output_string;  
     }
share|improve this question
6  
There is no limit to the number of shortcode (even same shortcode) in a page. If it doesn't work there is a problem in the function that handle the shortcode. Post it to have chance of any help... –  G. M. Sep 21 '13 at 11:42
    
Post it in the question. And post (the relevant part) of api-list.php. This code -pratically- do nothing. –  G. M. Sep 23 '13 at 12:49
add comment

1 Answer 1

up vote 1 down vote accepted

From the PHP Manual on require_once:

The require_once statement is identical to require except PHP will check if the file has already been included, and if so, not include (require) it again.

The second time your shortcode handler is run, the view/template will not be executed.
Hence no output.

Change
require_once "/front_end/view/api-list.php";
to
require "/front_end/view/api-list.php";
and you ought to be fine.

share|improve this answer
1  
Thank you so much it worked !! –  ram Sep 23 '13 at 13:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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