1

I've been struggling for quite a while how to make this work.

I created a custom php file, and used it as a template page. [below code]

I also ended up with this link //localhost/site/?page_id=43

If I want to query an id, I just need to add page_id=43&id=3 and it will display aa member name associated with the ID.

Whenever I query an ID, I only get {"result":[]} on that page.

Can someone check my code please?

/*
Template Name: getID
*/

    global $wpdb;
    if (isset($_GET['id']) === true && empty($_GET['id']) === false) {      
        $query = $wpdb->get_results("SELECT * FROM `memberid` WHERE `memberid` = `$_GET['id']`");

       $array = array();

       while ($row = mysqli_fetch_array($query)) {
        array_push($array, array('name' => $row [2]);
       }

       echo json_encode(array("result" => $array));
    }
2
  • There's a lot not WP compatible stuff in there. Where have you got that from? And use wp_send_json()
    – kaiser
    Sep 30, 2013 at 11:22
  • Btw, what exactly is the goal for that? Are you feeding that to some front end script library?
    – kaiser
    Sep 30, 2013 at 12:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.