请编写按标题获取帖子的函数
function get_page_by_post_title( $page_title, $output = OBJECT, $post_type = \'page\' ) {
global $wpdb;
$sql = $wpdb->prepare(
"
SELECT ID
FROM $wpdb->posts
WHERE post_title = %s
AND post_type = %s
ORDER BY ID DESC
",
$page_title,
$post_type
);
$page = $wpdb->get_var( $sql );
if ( $page ) {
return get_post( $page, $output );
}
}
这是inquire\\u id函数,
function get_inquiry_id($data){
$return = [];
$title=$data[\'title\'];
$return = get_page_by_post_title($title, OBJECT, \'inquiry\');
$return = $return->ID;
return new WP_REST_Response($return, 200);
}