Title: Problem with shortcode and php script
Last modified: September 19, 2017

---

# Problem with shortcode and php script

 *  [willy70](https://wordpress.org/support/users/willy70/)
 * (@willy70)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/problem-with-shortcode-and-php-script-please-help/)
 * Dear All,
    let me explain my little work with WordPress 4.4.10 and my problem.
 * I’d like to add to my web site a page to show some information about races
    reading
   values from custom tables inside wp instance. To do that I’ve prepared a shortcode
   adding these statements to functions.php file:
 *     ```
       function race_func() {
               ob_start();
               include('/var/www/html/wp-content/themes/twentyeleven/race.php');
               $var = ob_get_clean();
               return $var;
       }
       add_shortcode( 'race', 'race_func' );
       ```
   
 * I’ve made some test sith simple php code and I see that this short works fine
   
   but doesn’t work my final php script.
 * Inside “race.php” I’ve also two others php programms that I’ve to execute:
 *     ```
       <html>
       <head>
       <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
       <style type="text/css">
       </style>
       <script>
       function testoEvento(valore)
       {
           document.getElementById("testo_evento").innerHTML = '';
           $.ajax
           ({            
                   type: "POST",            
                   url: "test9369c.php",            
                   data: {id: valore},            
                   dataType: "html",            
                   success: function(dati_testo){    
                       $("#testo_evento").html(dati_testo);
                       return;    
                   },
                   error:function(msg){
                       alert('Errore : '+msg);
                   }
           }); 
           return;    
       ```
   
 *  ….omissis
 * but test9369c don’t run. I’ve already tried with some path without any improvements.
   
   Does Anybody know how can run php script that are inside this program ?
 * Thanks a Lot !!!
    Best Regards. Willy
    -  This topic was modified 8 years, 8 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
      Reason: put code in backticks
    -  This topic was modified 8 years, 8 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

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

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [8 years, 8 months ago](https://wordpress.org/support/topic/problem-with-shortcode-and-php-script-please-help/#post-9509672)
 * As you’re using JS can you show us the webpage with the problem?
 *  Thread Starter [willy70](https://wordpress.org/support/users/willy70/)
 * (@willy70)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/problem-with-shortcode-and-php-script-please-help/#post-9509736)
 * Dear Friend,
    of course, these are two capture first is OK but after make a selection
   instead of show the other information I got an error.
 * [First is OK](https://www.dropbox.com/s/1oo3doua1ganej2/wordpress_ok.png?dl=0)
 * [After Choose Year I got this error](https://www.dropbox.com/s/vdm8mfigt94kwjs/wordpress_error.png?dl=0)
 * All of my scripts php are in /var/www/html/wp-content/themes/twentyeleven/
 * Thanks so much for everything
    Best Regads
    -  This reply was modified 8 years, 8 months ago by [willy70](https://wordpress.org/support/users/willy70/).
    -  This reply was modified 8 years, 8 months ago by [willy70](https://wordpress.org/support/users/willy70/).
    -  This reply was modified 8 years, 8 months ago by [willy70](https://wordpress.org/support/users/willy70/).
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [8 years, 8 months ago](https://wordpress.org/support/topic/problem-with-shortcode-and-php-script-please-help/#post-9509808)
 * Oh sorry for not being clear, I meant to see the website and not a screenshot.
 *  Thread Starter [willy70](https://wordpress.org/support/users/willy70/)
 * (@willy70)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/problem-with-shortcode-and-php-script-please-help/#post-9509905)
 * Dear Andrew,
    my English is bad my apologize! If you want to see my website ,
   for a lot of reasons , you must add this entry in your /etc/hosts file:
 * 193.205.222.189 atleticaumbertide.it
 * the page is: [http://atleticaumbertide.it/grandprixtest/](http://atleticaumbertide.it/grandprixtest/)
 * This server is up for a few days for debugging purpose in my virtual machine.
 * Thanks again
 * Best Regards
    Willy
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/problem-with-shortcode-and-php-script-please-help/#post-9511292)
 * I didn’t check your site, but I see a couple possible problems in the jQuery 
   you posted. You generally shouldn’t load jQuery from a third party source. WP
   has its own version within its installation on your server. Using another version
   creates conflicts if you are not careful. The proper WP way of using jQuery means
   enqueuing your script with [wp_enqueue_script()](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)
   and specifying `['jquery']` as a dependency. The WP version runs in noConflict
   mode, so you must explicitly refer to `jQuery` and not use the `$` shortcut, 
   unless you use a “noConflict wrapper”. See the first user note in the above linked
   reference.
 * That said, what you have will likely work fine as far as JS is concerned, but
   it’s not “The WordPress Way™” Where your problem likely lies is in your test9369c.
   php Ajax handler. If it uses any WP resources in any way, the WP environment 
   is not properly initialized and attempts to use WP resources will likely fail.
   All WP Ajax requests must pass through _/wp-admin/admin-ajax.php_. Your data 
   must include an “action” value, which is used to construct an action handle which
   you hook in order to cause your PHP code to execute. Please review the [Ajax section](https://developer.wordpress.org/plugins/javascript/ajax/)
   of the Plugin Handbook. It applies equally to theme code if that is where your
   code resides.

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

The topic ‘Problem with shortcode and php script’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [8 years, 8 months ago](https://wordpress.org/support/topic/problem-with-shortcode-and-php-script-please-help/#post-9511292)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
