Automatic focus keywords

#374514
  • Resolved mkgf
    Rank Math free

    Hello, we have implemented your automatic focus key from product title code but it seems to have added focus keywords of other prodct names. That is focus keyword for product A is B while that of product B is A.

    We are also getting the following error in log

    /home/eef/public_html/website.co.uk/wp-content/themes/store/functions.php on line 400, pointing to an error in your code.


    /**
    * Function to automatically update the focus keyword with the product title
    */
    function update_focus_keywords()
    {
    $posts = get_posts(array(
    'posts_per_page' => -1,
    'post_type' => 'product' //replace post with the name of your post type
    ));
    foreach ($products as $p) {
    update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower(get_the_title($p->ID)));
    }
    }
    add_action('init', 'update_focus_keywords');

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    That code has been tried and tested on multiple installations and plenty of our users already use it to set automatic focus keywords.

    If it’s not working on your website you need to check the database and even try running a simple function that calls the function get_the_title() to check that everything is being returned correctly.

    ​​​​​​​Regarding the error message, that doesn’t say what the error is and simply shows the line number.

    Please share the full error log for that line number so we can advise further.

    Looking forward to hearing back from you.

    mkgf
    Rank Math free

    Hello,

    The error is on Line 400 which is

    foreach ($products as $p) {
    update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower(get_the_title($p->ID)));

    Hello,

    As mentioned by my colleague you are pointing to the actual line of code where the error is. We need to know the error message that line produced.

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    mkgf
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Nigel
    Rank Math business

    Hello,

    Thank you for your patience as we look into you issue.

    I fixed a mistake in the code snippet which prevented it from functioning correctly by replacing the variable “$posts” with “$products”.

    Hope that helps. Please let us know if you have questions.

    mkgf
    Rank Math free

    Sorry, I don’t think I follow. What line was this please?

    This is the code we had;

    
    /**
    * Function to automatically update the focus keyword with the product title
    */
    function update_focus_keywords()
    {
    $posts = get_posts(array(
    'posts_per_page' => -1,
    'post_type' => 'product' //replace post with the name of your post type
    ));
    foreach ($products as $p) {
    update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower(get_the_title($p->ID)));
    }
    }
    add_action('init', 'update_focus_keywords');

    Where did you change please?

    Nigel
    Rank Math business

    Hello,

    There is/was only one instance of “$posts” in the whole snippet. Check the sixth line.

    Please let us know if you have questions. We are here to help.

    mkgf
    Rank Math free

    Oh I see it now.
    $posts = get_posts(array(
    to
    $products = get_posts(array(

    Many thanks for your assistance.

    mkgf
    Rank Math free

    In continuation wit the above, I have gone through the products and see an issue with the automatically populated Title & Description

    ERROR

    In this example, the product concerned is

    Bath & Body Works – Teakwood Shower Gel for Men

    However, the title shown in the snippet in image above states

    Bath & Body Works – Noir Shower Gel for Men

    This is a totally different product. How has this happened and how can it be solved please?

    I have over 600 products to deal with here.

    Hello,

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    mkgf
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    mkgf
    Rank Math free

    Please, check mid products as I have been manually fixing the first few

    Hello,

    The login link that you have created for us is not working and redirecting to the login page. Please check and share a new login link so we can check this further.

    Looking forward to helping you.

    mkgf
    Rank Math free

    You guys do take your sweet time.

    I have exported the product csv and manually added %title% into the seo_title column then added %excerpt% into the description column for all 1090 products.

    Imported it back and it seems to have solved the problem.

    Though the issue should never have occurred in the first place.

    Do you think this solution will be detrimental in any way?

    Hello,

    We had a great influx of tickets and since we have to give priority support to the paid users sometimes in the Free forums the waiting time gets over 24 hours.

    Regarding the issue from this ticket, adding the variables via CSV import shouldn’t cause any issues as long as everything gets saved in the database correctly.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 15 replies - 1 through 15 (of 15 total)

The ticket ‘Automatic focus keywords’ is closed to new replies.