Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create a shortcode to display child pages, so far works like charm, however, I passing a value called 'parent' as response for 'post_parent', by default I need to display the current post ID, however if the user pass the parameter for sample [shortcode parent=5] the shortcode display childs of the post with ID 5.

Problem: If I set parent to X value, so far works like charm, however by Default, it doesn't assign any parameter.

Any guessing?

Thanks in advanced.

This is the code, I don't think is necessary to copy all since is really long, I'm just copying the query part.

 function andrew_child_loop_shortcode ( $atts ) {
   extract ( shortcode_atts (array (
    'parent' => **$thePostID**,       
    'posts' => 20

      ), $atts ) );
      $output = '<div class="clear"></div>';
         $args = array(
            'orderby' =>  'menu_order',
            'order' => 'ASC',
            'post_parent' => $parent,
            'post_type' => 'page',
            'posts_per_page' => $posts
           );
      **global $post;
      $thePostID = $post->ID;**
      $andrew2_query = new  WP_Query( $args );

What is marked with black **, is what I thought could be the solution, however is not working.

share|improve this question
2  
Have you tried shifting the global $post; $thePostID = $post->ID; to the top of the function. – Joshua Abenazer Dec 6 '11 at 5:59
I did not even think about it... however it worked great! thanks a ton :) – andrewkthx Dec 6 '11 at 6:03

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.