• 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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    As you’re using JS can you show us the webpage with the problem?

    Thread Starter willy70

    (@willy70)

    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

    After Choose Year I got this error

    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 7 years, 2 months ago by willy70.
    • This reply was modified 7 years, 2 months ago by willy70.
    • This reply was modified 7 years, 2 months ago by willy70.
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Oh sorry for not being clear, I meant to see the website and not a screenshot.

    Thread Starter willy70

    (@willy70)

    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: https://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

    (@bcworkz)

    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() 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 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.