-
Hey
I have searched high and low and been unable to find an answer.
I am looking to get keywords automatically updated on any new posts submitted with frontend submit with the title of the post and tags.
Unsure if this is possible but found the below codes but unsure if they are correct for my post.
Thanks
In advance for your help.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){
if(get_the_tags($p->ID)){
foreach((get_the_tags($p->ID)) as $tag) {
$keywords[] = strtolower($tag->name);
}
update_post_meta($p->ID,’rank_math_focus_keyword’,implode(“, “, array_unique($keywords)));
}
}}
add_action( ‘init’, ‘update_focus_keywords’ );Or
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){
if(get_the_tags($p->ID)){
foreach((get_the_tags($p->ID)) as $tag) {
$keywords[] = strtolower($tag->name);
}
update_post_meta($p->ID,’rank_math_focus_keyword’,implode(“, “, array_unique($keywords)));
}
}}
add_action( ‘init’, ‘update_focus_keywords’ );
The ticket ‘Focus keywords’ is closed to new replies.