2

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.

1
  • I've seen examples using add_filter to register the shortcode with the priority added to the filter call. Commented May 3, 2017 at 9:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.