0

我在 WordPress 上有一个嵌入式采访(如联系表格),我使用点击功能将 div 的文本值设置为具有焦点的采访输入字段的名称。

我创建了一个 PHP 插件,其目的是从 WordPress 获取名称并返回一个定义(托管在 Notion 数据库上)。

我不知道如何在单击(/值更改)时从该 WordPress div 中获取值并将其传递给 PHP 插件以用作过滤器(键),以便我能够返回定义。

$databaseId = "BBB";
$url = "https://api.notion.com/v1/databases/$databaseId/query"; //api endpoint
$token = 'AAAA';
$version = '2021-08-16';
$contentType = "Content-type: application/json";



// value to be gotten from Wordpress
$dataElementName = $_REQUEST['q'];



// ADD INTEGRATION TO GET VALUE



//post data
$data_array =
['filter' =>
[
"property"=>"DataElement",
"title"=>["equals"=>$dataElementName]
]
];



$data = json_encode($data_array);



//intialize cURL
$ch = curl_init();



curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//below is for posting
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);



curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // Remove when push to wordpress
//auth header notionAPI
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token,
'Notion-Version: '.$version,$contentType));



//output
$resp = curl_exec($ch);



//error check
if($e = curl_error($ch))
{
echo $e;
} else
{
$decoded = json_decode($resp, true);
//var_dump($decoded);
//meaning will be passed to Javascript for Output
$meaning = $decoded['results'][0]['properties']['Meaning']['rich_text'][0]['text']['content'];
echo $meaning;
}

curl_close($ch);

任何意见是极大的赞赏。

4

0 回答 0