update Focus Keyword by multiple taxonomies attached to the post
-
hello,
according to this page I want to update my Focus Keyword according to the logic of this pagein the logic of things and the code
I should see this (example) Focus Keyword : [for rent] [apartment] [paris,france]but something prevents or does not want this code to work
all the AIs I tested could not detect where the error is
so I assume that ranckmath blocks this logic?My code
/**
* Function to update Rank Math Focus Keywords for properties using specified taxonomies
*/
function update_property_focus_keywords() {
$properties = get_posts(array(
'post_type' => 'property',
'posts_per_page' => -1,
'post_status' => 'publish'
));
$taxonomies = array('property-status', 'property-type', 'property-city');
foreach ($properties as $property) {
// Check if Focus Keyword is already set
if (!get_post_meta($property->ID, 'rank_math_focus_keyword', true)) {
$keywords = array();
// Get terms for each taxonomy
foreach ($taxonomies as $taxonomy) {
$terms = get_the_terms($property->ID, $taxonomy);
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term) {
$keywords[] = strtolower($term->name);
}
}
}
// Update Focus Keyword if we have keywords
if (!empty($keywords)) {
$focus_keyword = implode(', ', array_unique($keywords));
update_post_meta($property->ID, 'rank_math_focus_keyword', $focus_keyword);
}
}
}
}
// Hook the function to run when WordPress initializes
add_action('init', 'update_property_focus_keywords');
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.