WordPress.org

Ready to get started?Download WordPress

Forums

My code is not working in wordpress (7 posts)

  1. peacehunter
    Member
    Posted 1 year ago #

    I am trying to fetch some information from database in wordpress. I used jquery for sending ajax request and fetch the data from php file named values.php . My php code is below

    http://pastebin.com/LFJmC9Fu

    But after sending ajax request the php file sends me nothing. For testing I have added "echo 'test';" , but it does not display. When I remove or write the code "echo 'test'" at top of this code "require_once($path.'/wp-config.php');" then it works, I mean "echo 'test';" shows. That means the problem is in require_once.

    I have tried many ways for solve this problem, but nothing works.
    Please give me suggestion what should I do now.

  2. Hariprasad
    Member
    Posted 1 year ago #

    Hi,
    Where you saved this php file? Can you show the javascript code?

  3. peacehunter
    Member
    Posted 1 year ago #

    I have saved the file in theme folder.

    /themes/GeoTheme/values.php

    my javascript code below,

    var value_tuh=document.getElementById("sr_tuh").value;
    jQuery("#content").load("<?php bloginfo('template_directory');?>/values.php",{s:value_tuh});

    I am using child theme.

  4. Hariprasad
    Member
    Posted 1 year ago #

    You are sending value via variable 's' and retrieving it using 'q'.
    Check the code

    if($_GET['q']){
            autocompleter();
    }
  5. peacehunter
    Member
    Posted 1 year ago #

    I have fixed that, but still having same problem. :(

  6. Hariprasad
    Member
    Posted 1 year ago #

    Check this link

    http://wordpress.org/support/topic/using-wordpress-for-custom-database-queries?replies=9
    It says

    You can include almost all of the wordpress code by simply adding this to the top of any PHP file:
    require('./wp-blog-header.php');

    Try it

  7. peacehunter
    Member
    Posted 1 year ago #

    I have tried it. But its not working. After including this file, nothing happen. But if I write any code at the top of "require" then it works.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags