ajax_get_keyword_usage_and_post_types()
Retrieves the post ids where the keyword is used before as well as the types of those posts.
Хуков нет.
Возвращает
null. Ничего (null).
Использование
ajax_get_keyword_usage_and_post_types();
Код ajax_get_keyword_usage_and_post_types() ajax get keyword usage and post types Yoast 26.3
function ajax_get_keyword_usage_and_post_types() {
check_ajax_referer( 'wpseo-keyword-usage-and-post-types', 'nonce' );
if ( ! isset( $_POST['post_id'], $_POST['keyword'] ) || ! is_string( $_POST['keyword'] ) ) {
exit( '-1' );
}
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- We are casting to an integer.
$post_id = (int) wp_unslash( $_POST['post_id'] );
if ( $post_id === 0 || ! current_user_can( 'edit_post', $post_id ) ) {
exit( '-1' );
}
$keyword = sanitize_text_field( wp_unslash( $_POST['keyword'] ) );
$post_ids = WPSEO_Meta::keyword_usage( $keyword, $post_id );
$return_object = [
'keyword_usage' => $post_ids,
'post_types' => WPSEO_Meta::post_types_for_ids( $post_ids ),
];
wp_die(
// phpcs:ignore WordPress.Security.EscapeOutput -- Reason: WPSEO_Utils::format_json_encode is safe.
WPSEO_Utils::format_json_encode( $return_object )
);
}