Hello,
Thank you for your query and we are so sorry about the trouble this must have caused.
The variable %customfield%
works best if the return value is a string type. Since your custom fields return an array and not string, you may need to work on a different approach.
We can make a custom variable that parses the array and makes sure it returns a string. Please refer to the custom code we created below:
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'rm_motor', [
'name' => esc_html__( 'Author name', 'rank-math' ),
'description' => esc_html__( 'Author description', 'rank-math' ),
'variable' => 'rm_motor', /* the actual variable: %rm_motor% */
'example' => rm_motor_call_back(),
],
'rm_motor_call_back'
);
});
function rm_motor_call_back(){
global $post;
$motorValue = get_field('motor', $post->ID)[0];
return $motorValue;
}
So instead of %customfield(motor)%
, you’ll have to use the custom %rm_motor%
variable.
You may refer to this guide on how to add filters to your website: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Please note that you will not see the value on the backend preview when applying this variable but you should see it on the frontend working.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
hello and thank you for the reply and suggestion. If nothing else will work then i will definitely implement this! However, although you are correct that it is apparently returning an array wehn used for the Seo Title, I am a bit confused since:
1) under the admin settings for the custom field i definitely selected VALUE as the return value on front end
Return Value
Value
Label
Both (Array)
Specify the returned value on front end
2) It displays the return VALUE, ie not as an array with label, just fine everywhere else on the website.
Given this, is there by chance an easier, or at least more globally applicable solution, that i can use instead of hard-coding in the addional variables for every field i want to use in the SEO title?
Hello,
The value of the Checkbox field is saved as an array in the postmeta table, and that’s why it can’t be fetched with the customfield variable. Please use the filter shared by my colleague to create a custom variable.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
thank you for the clarification. If I change the field type to Select (NOT Multi-select) should it work out of the box?
Hello,
If the field type is “Select”, i.e. just one item – then it shouldn’t be outputted as an array. If that is the case, it should work out of the box.
Thank you for your patience and cooperation
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.