Hello,
Thank you for contacting Rank Math and bringing your concern to our attention.
Unfortunately, we don’t have a variable for getting the primary category of the product.
However, you can use this filter to create a new variable on your site which displays the selected primary category:
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'my_primary_term', [
'name' => esc_html__( 'Custom variable name.', 'rank-math' ),
'description' => esc_html__( 'Custom variable description.', 'rank-math' ),
'variable' => 'my_primary_term', /* the actual variable: %my_primary_term% */
'example' => my_primary_term_call_back(),
],
'my_primary_term_call_back'
);
});
function my_primary_term_call_back(){
global $post;
return get_cat_name(get_post_meta( $post->ID, 'rank_math_primary_category', true ));
}
Here’s a guide on how to add a filter to your site:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Once done, you can use this variable %my_primary_term%to retrieve the primary term.
Hope that helps.
Thank you.
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.