-
Hello everyone. To be honest, this is not a support question per se. Is more of a “help me if you can” one.
Following this guide I’ve been able to automate the insertion of the site title as focus keyword to a custom post type named
podcast
, if no focus keyword has been set.What I am trying to achieve is to add to the focus keywords also a custom taxonomy I’ve created for
poodcast
CPT calledcategorie-podcast
.I’m using ACF to create both the CPT and the Custom Taxonomies associated to it.
The code I have right now is
/**
* Function to automatically update the RankMath focus keyword of "podcast" cpt with the site title, if no focus keyword is set
*/
function update_site_title_focus_keywords() {
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'podcast' // Only for post type "podcast"
));// Get the site title
$site_title = get_bloginfo('name');foreach ($posts as $p) {
// Check if Rank Math keyword already exists and only update if it doesn't have it
$rank_math_keyword = get_post_meta($p->ID, 'rank_math_focus_keyword', true);
if (!$rank_math_keyword) {
// Set the focus keyword to the site title
update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower($site_title));
}
}
}add_action('init', 'update_site_title_focus_keywords');
Any help would be appreciated
The ticket ‘Automatically add site title and custom taxonomy as keywords’ is closed to new replies.