Title: Timing problem with code imported from Shortcode-exec-PHP
Last modified: October 20, 2017

---

# Timing problem with code imported from Shortcode-exec-PHP

 *  [liegeman](https://wordpress.org/support/users/liegeman/)
 * (@liegeman)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/timing-problem-with-code-imported-from-shortcode-exec-php/)
 * I have been using the following code in Shortcode Exec PHP to generate a context-
   sensitive menu which displays the ancestry of the current page, plus with its
   immediate siblings and children. Having imported this, the code looks identical:
   but the menu now displays every single page in the family tree, making it impracticably
   long! So I’ve had to revert to Shortcode Exec PHP for now.
 * I’m guessing this may be something to do with precisely when the code is being
   executed: but I can’t see any options for controlling this. Is there a simple
   fix?
 *     ```
       //CONTEXT MENU code - defined as 'context_menu' in Shortcode Exec PHP
       //Invoked as [context_menu] in Sidebar Right text widget
   
       //if the post has no parent - it's a top-level page
       if(!$post->post_parent){
         $relations = array(); // no ancestors
         //Search the database for any child and other top-level pages
         global $wpdb;
         $result = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_parent = $post->ID OR post_parent = 0)" );
   
       }else{
         //Tricky - First, request array of ancestor pages
         $relations = get_post_ancestors($post->ID);
         //Now search the database for any child and sibling pages
         global $wpdb;
         $result = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE (post_type='page' OR post_type='post') AND (post_parent = $post->ID OR post_parent = $post->post_parent)" );
       }
   
       if ($result){
         //Add any finds to the array
         foreach($result as $pageID){
           array_push($relations, $pageID->ID);
         }
       }
       //Reduce array to a comma delimited list
       $relations_string = implode(",",$relations);
       //Now request a list of the collected pages, wrapped in <li> tags 
       $sidelinks = wp_list_pages("title_li=&echo=0&include=".$relations_string);
       if ($sidelinks) { ?>
         <ul id="ContextMenu">
           <? //Not an empty list, so wrap it in <ul> tags
           echo $sidelinks; ?>
         </ul>         
       <? }
       ```
   
    -  This topic was modified 8 years, 7 months ago by [liegeman](https://wordpress.org/support/users/liegeman/).
      Reason: Used wrong tags to enclose code
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ftiming-problem-with-code-imported-from-shortcode-exec-php%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [liegeman](https://wordpress.org/support/users/liegeman/)
 * (@liegeman)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/timing-problem-with-code-imported-from-shortcode-exec-php/#post-9606382)
 * Sorry – I initially used b-quote instead of code tags. The code shown above is
   now correct: but the problem is as previously described.
    -  This reply was modified 8 years, 7 months ago by [liegeman](https://wordpress.org/support/users/liegeman/).
 *  Thread Starter [liegeman](https://wordpress.org/support/users/liegeman/)
 * (@liegeman)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/timing-problem-with-code-imported-from-shortcode-exec-php/#post-9615936)
 * I’ve now managed to work around my problem by using the Advanced Sidebar Menu
   plugin to insert a widget with comparable functionality in place of my ‘Context
   Menu’ shortcode. I’m de-installing Shortcode Exec PHP, but retaining Add Shortcodes
   Actions And Filters for possible future use; so would still be interested if 
   anyone can offer any insight as to what may have caused the above incompatibility
   and how to fix it.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Timing problem with code imported from Shortcode-exec-PHP’ is closed 
to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/add-actions-and-filters_ffffff.svg)
 * [Add Shortcodes Actions And Filters](https://wordpress.org/plugins/add-actions-and-filters/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/add-actions-and-filters/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/add-actions-and-filters/)
 * [Active Topics](https://wordpress.org/support/plugin/add-actions-and-filters/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/add-actions-and-filters/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/add-actions-and-filters/reviews/)

 * 2 replies
 * 1 participant
 * Last reply from: [liegeman](https://wordpress.org/support/users/liegeman/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/timing-problem-with-code-imported-from-shortcode-exec-php/#post-9615936)
 * Status: not resolved