update Focus Keyword by multiple taxonomies attached to the post

[ad_1]

hello,
according to this page I want to update my Focus Keyword according to the logic of this page

in 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');

  • This topic was modified 14 hours, 49 minutes ago by neosan.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer