Dynamically Override Fancy Title – Part II

I finally got it. The final version of the function is:

<?php 

// ACCOMODATION TITLE
add_filter ('presscore_get_page_title','netbooking_presscore_get_page_title',10,1);
function netbooking_presscore_get_page_title ( $title ) {
if(  is_page( '1057' ) ){

        $GLOBALS["content"] = $content;

        // This reads input considering a default value in case of error


$INPUT = function($param, $default, $prefix = true){
                $key = $prefix ? 'netbooking_structure_'.$param : $param;
                return isset($GLOBALS["content"][$key]) ? $GLOBALS["content"][$key] : $default;
            };

        // Read input GET
        $language = $INPUT('language', 'it', false);
        $lang = substr($language, 0, 2);
        $upwd = $INPUT('upwd', '8UDW37tF', false);
        $cryptedID = $INPUT('crypted_id', 'Nel6LjH9xZ4=', false);
        $structure_id = $INPUT('sid', 268, false);
        $accomodation_id = $INPUT('aid', '4894', false);

        // XML accomodation
        $today = getdate();
        $api = 'http://';
        $query = http_build_query([
            'get' => 'getaccomodation',
            'upwd' => $upwd,
            'id' => $structure_id,
            'idacc' => $accomodation_id,
            'type' => 'p',
            'mode' => 'xml',
            'ukey' => 'create',
            'l' => $lang,
            'dstart' => $today['mday'],
            'mstart' => $today['mon'],
            'ystart' => $today['year'],
        ]);
        $xml = new SimpleXMLElement(file_get_contents($api. '?' . $query));



        // Imposto il locale
        setlocale(LC_TIME, $language);

 $url="htp://";

$xml = simplexml_load_file($url);

$nomestruttura=(string)$xml->accomodation->name_struct;
$nome=(string)$xml->accomodation->name;

$title=$nomestruttura." ".$nome;

    }   
  return $title;
         }
         ?>

I understood the mistake is in the function to get the xml. Now I have to solve this.
EDIT & SOLVED

    // ACCOMODATION TITLE
add_filter ('presscore_get_page_title','netbooking_presscore_get_page_title',10,1); // filter for title
function netbooking_presscore_get_page_title ( $title ) { // function to override title
if(  is_page( icl_object_id('1057')) ){ // Conditional output with ICL support
// Added Query 

                global $wp_query; 

    // Get Values
    $content = [];
    $content["crypted_id"] =   get_option('netbooking_'.'home'.'_crypted_id_meta');
    $content["upwd"] =         get_option('netbooking_'.'home'.'_upwd_meta');
    $content["structure_id"] = get_option('netbooking_'.'home'.'_structure_id_meta');
    $content["language"] = netbooking_get_language();
    $content["sid"] = isset($_GET['sid']) ? $_GET['sid'] : $wp_query->query_vars['sid'];
    $content["aid"] = isset($_GET['aid']) ? $_GET['aid'] : $wp_query->query_vars['aid'];
    foreach ($GLOBALS['structure'.'-options'] as $key => $option) {
        $content[$key] = get_option($key);
}


        $GLOBALS["content"] = $content;

        // Function to read default values in case of error
        $INPUT = function($param, $default, $prefix = true){
            $key = $prefix ? 'netbooking_structure_'.$param : $param;
            return isset($GLOBALS["content"][$key]) ? $GLOBALS["content"][$key] : $default;
        };

        // GET Input
        $language = $INPUT('language', 'it', false);
        $lang = substr($language, 0, 2);
        $upwd = $INPUT('upwd', '8UDW37tF', false);
        $cryptedID = $INPUT('crypted_id', 'Nel6LjH9xZ4=', false);
        $structure_id = $INPUT('sid', 268, false);
        $accomodation_id = $INPUT('aid', '4894', false);

        // Accomodation XML 
        $today = getdate();
        $api = 'http://myurl.it';
        $query = http_build_query([
            'get' => 'getaccomodation',
            'upwd' => $upwd,
            'id' => $structure_id,
            'idacc' => $accomodation_id,
            'type' => 'p',
            'mode' => 'xml',
            'ukey' => 'create',
            'l' => $lang,
            'dstart' => $today['mday'],
            'mstart' => $today['mon'],
            'ystart' => $today['year'],
        ]);
        $xml = new SimpleXMLElement(file_get_contents($api. '?' . $query));

        // Imposto il locale
        setlocale(LC_TIME, $language);


$nomestruttura=(string)$xml->accomodation->name_struct;
$nome=(string)$xml->accomodation->name;

$title=$nomestruttura." ".$nome;

    }   
  return $title;
         }

This finally Works!

Leave a Comment