Is it possible to delay execution of shortcode output callback?

I have a problem : shortcode output callback triggered too early.

/* Defined in plugin constructor */ 
    add_shortcode( 'foobar' , array($this,'pre_render_routine'));
    function pre_render_routine () {/* Do something*/}

Before shortcode will be displayed , must be requested information about metafields which displayed in current main loop :

add_action( 'loop_end', array($this,'retrieve_metadata') );
 function retrieve_metadata( WP_Query $wp_query ) {

            if( is_main_query() && $wp_query->found_posts > 0 ) {

                $GLOBALS['collected_metafields'] = array();
                foreach($wp_query->posts as $post) {
                    $GLOBALS['collected_metafields'][] = array_keys(wp_cache_get($post->ID,'post_meta'));
                }

            }

    }

P.S. After all the information has been received , I need output plugin markup at the same place where the shortcode.

0

Leave a Comment