• Resolved neosan

    (@nreljed)


    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 3 months, 3 weeks ago by neosan.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @nreljed,
    ?
    Thank you for contacting Rank Math support.
    ?
    The code is correct and should add the focus keyword to the property post type. We tested it on our end by creating the post type with the same slug and taxonomies. If it isn’t working on your end, please make sure that the slugs of the post type and taxonomies are correct.
    ?
    Also, the code will add each taxonomy as a separate focus keyword. If you want to merge them in a single keyphrase, then use space (" ") as a separator instead of the comma while imploding the keywords array.
    ?
    Let us know how that goes. Looking forward to helping you.

    Thread Starter neosan

    (@nreljed)

    hello @rankmathsupport ,
    I come back to you to confirm that there is potentially a problem
    I can’t determine where it comes from but I notified pods
    in reality you confirmed that it works and it is (probably under ACF or another plugin ) what i tested and it worked the first time

    see the image

    in pods there was the update 3.2.4 – July 15th, 2024
    Feature: Add support for Post Types that have associated Taxonomies to have a Relationship field which will automatically sync to the corresponding taxonomy on save.

    can you do the test and confirm that rankmath really sees the pods terms and the snippet works?Technically you should do it without worries, if it works

    if not are you able to understand what instructions are missing to make it functional?
    it may be possible that we need another code snippet for pods ?

    looking forward to hearing from you

    • This reply was modified 3 months, 3 weeks ago by neosan.
    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @nreljed,
    ?
    That change doesn’t affect the behavior of this filter as the function that gets the taxonomies still retrieves the data correctly.
    ?
    If this is not working on your website you might need to debug this at the code level and dump the variables at different stages of the function to see where it’s failing to retrieve the data.
    ?
    Don’t hesitate to get in touch if you have any other questions.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.