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'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() );
        endwhile;
    }
    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.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

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;
share|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
add comment

If you have defined a shortcode like this:

 add_shortcode('myshortcode','pa_insertPage');

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

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

as a way to retrieve the $output.

share|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
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.