I'm trying to get my head around a fairly simple concept in PHP but I'm pretty green.

I have a function..

function pa_insertPage($atts, $content = null) {
    // Default output if no pageid given
    $output = NULL;
    // extract atts and assign to array
    extract(shortcode_atts(array("page" => '2404' // Value for Course Descriptions page
    ), $atts));
    // if a page id is specified, then run query
    if (!empty($page)) {
        $pageContent = new WP_query();
        $pageContent->query(array('page_id' => $page));
        while ($pageContent->have_posts()) : $pageContent->the_post();
            // assign the content to $output
            $output = apply_filters( 'the_content', get_the_content() );
    return $output;

And I'd like to use the returned $output from this function in another function called naada_assess()

In my naada_assess function I've called $recClasses = pa_insertPage($output); but that doesn't seem to do the trick.


This isn't really a WordPress question... that said

$recClasses = pa_insertPage($output);

is incorrect. here you should be passing to insertPage whatever the arguments are. Then insertPage will return $output, making $recClasses the same value as $output.

    $recClasses = pa_insertPage('your attributes');
// $recClasses now equals $output;
| improve this answer | |
  • Might be a WordPress question... looks like a shortcode callback to me. – s_ha_dum Mar 28 '13 at 20:53
  • Thanks Vancoder! Yes I understood it to be a PHP question, but I haven't yet found a good PHP help forum. Do you know of any? Your response took care of my issue easily and highlighted my poor ability to see and understand the problem. – Andrew-ThinkUp Mar 29 '13 at 15:42
  • @s_ha_dum Yes it is a WP shortcode, but I decided not to use it as such, but have it's output be placed into another function. – Andrew-ThinkUp Mar 29 '13 at 15:44

If you have defined a shortcode like this:


then you could try this inside your naada_assess() function:

$recClasses = do_shortcode('[myshortcode page="123"]');

as a way to retrieve the $output.

| improve this answer | |
  • thanks! This looks to easily accomplish the same thing. Everytime I struggle and ask for help, I see that there isn't only 1 way to solve the problem. – Andrew-ThinkUp Mar 29 '13 at 15:45

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.