Json+ld
-
I am creating a plugins where I use several select in the plugin administration panel, I have a function that shows the select and I use an ajax script where I pass values to a B file where I receive the values and with functions I build the json, but in the point where they receive the values arrive empty.
B file:
//We get the input data
$select_1 = $_GET[“select_1”];
$select_2 = $_GET[“select_2”];
$select_3 = $_GET[“select_3”];
echo $select_1;
echo $select_2;//I verify that the data arrives well
echo $select_3;
function theme_head_script($select_1,$select_2,$select_3){
// We make the necessary checks … (sanitize the texts to avoid XSS and code injections, check that the age is a number, etc.)
// Omitted for code brevity
// BUT DON’T FORGET THAT IT IS SOMETHING IMPORTANT.
// Set the “content-type” header as “JSON” so that jQuery recognizes it as suchheader(‘Content-Type: application/json’);
// We save the data in an array
$datos = array(‘@context’=> ‘https://schema.org’,
‘@type’=> ‘CollegeOrUniversity’,
‘sameAs’ => $select_1,
‘address’ => [
‘@type’=> ‘PostalAddress’,
‘streetAddress’=> $select_2,
‘addressLocality’=> $select_3,
‘addressRegion’=> ‘Estado Carabobo’,
‘postalCode’=> ‘2005’,
‘addressCountry’=> ‘VE’
]);
// We return the array passed to JSON as an objectecho json_encode($datos, JSON_FORCE_OBJECT);
// Always die in functions echoing ajax content}
add_action( ‘wp_head’, ‘theme_head_script’ );
//Also in the function of add_action does not recognize it as one within the context of wordpress.//Do you have any idea how you can help me .. thanks
- The topic ‘Json+ld’ is closed to new replies.