-
I have created custom field named ”focus_keywords” (screenshot-https://snipboard.io/3uIxqT.jpg and https://snipboard.io/mScQ8d.jpg) with the help of Advanced Custom Fields Plugin to add multiple keywords in rank math focus keywords from custom field text box, for new draft and publish articles.
I Got this below code from Rank math AI chat box and I added in rank-math.php
function update_focus_keywords() {
$posts = get_posts(
array(
‘posts_per_page’ => -1,
‘post_type’ => ‘post’, // replace post with the name of your post type.
)
);
foreach ( $posts as $p ) {
// Replace ‘focus_keywords’ with your ACF field name.
if ( ! get_post_meta( $p->ID, ‘rank_math_focus_keyword’, true ) && function_exists( ‘get_field’ ) && ( null !== get_field( ‘focus_keywords’, $p->ID ) ) ) {
update_post_meta( $p->ID, ‘rank_math_focus_keyword’, strtolower( get_field( ‘focus_keywords’, $p->ID ) ) );
}
}
}
add_action( ‘init’, ‘update_focus_keywords’ );But it’s not working.
The ticket ‘custom Field for Focus Keywords’ is closed to new replies.