category product count to title

#221800
  • Resolved Stephen
    Rank Math free

    Hi

    Is it possible to add the total product count of a particular category to be used as a variable for the title/description fields?

    I can see a meta key of “product_count_product_cat” but not seeing that come up in the list of variables available.

    Cheers!
    Stephen

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

    Thank you for contacting Rank Math support today. We are happy to help you.

    I’m sorry but we do not have that variable in the plugin.

    You may need an expert to code a custom variable for that. Please refer to this ticket page: https://support.rankmath.com/ticket/adding-custom-variable/

    Or, you might want to check this with the WooCommerce team and see if they have a solution for you.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    thanks for pointing me in the right direction

    in case it helps someone else finding this post i got this bit of code working for me:

    /**
     * Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
    * Snippet to register variable that will return all terms in custom taxonomy
     */
    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'post_content',
    	   [
    	   'name'        => esc_html__( 'product count', 'rank-math' ),
    	   'description' => esc_html__( 'description', 'rank-math' ),
    	   'variable'    => 'post_content',
    	   'example'     => post_content_callback(),
    	   ],
    	   'post_content_callback'
       );
    });
    function post_content_callback(){
    	$category = get_queried_object();
        $category_id = $category->term_id;
    	$content = get_term( $category_id , 'product_cat');
    	return $content->count;
    }

    also im not an expert or a coder so use at your own risk! 🙂

    Hello,

    We are glad to be of help with this issue.

    If you don’t mind us asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘category product count to title’ is closed to new replies.