1

I am going through strange problem. I have defined the function in function.php inside theme directory.

function.php

function db_cache($keys, $value) {
   global $wpdb;
   $value = base64_encode(serialize($value));
   $res = $wpdb->insert("db_cache", array("keys" => $keys, "value" => $value), array("%s", "%s"));
}

I made one wordpress template which decides which file to be included. suppose page link for given template is,

get_permalink(23).'?action=book_hotel'

In this template,

class func{
   function book_hotel(){
       include_once get_template_directory() . "/custom/agent/tpl-hotelbook.php";
   }
}

if($_GET['book_hotel')) {
   $obj = new func();
   $obj->book_hotel();
}

Again in,

tpl-hotelbook.php

 db_cache("key", $value);    //when I call db_cache function insert query is executed more than once. Sometimes executes 2, and sometime query executes 3 time. what would be the problem?

I have checked if the function was called multiple times using die at last of db_cache function. But multiple function call was not the issues. Thank you.

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.