• Resolved drakeman85

    (@drakeman85)


    Hello,
    Im using your progin with RankMath seo but I see some problems.

    I have added this code to functions.php but I see this error in the snippet test:

    “Invalid object type for fielnd “itemReviewed””

    Can you help me please fix Snippet code to be valind with RankMath for products and articles visitor’s rankings?

    add_filter( "rank_math/snippet/rich_snippet_product_entity", "custom_kksr_rating");
    
    function custom_kksr_rating ( $entity ) {
    	
    	$id = get_the_ID();
    	$temprend = get_post_meta('kksr_sd');
    	//var_dump($temprend);
    
    	$i = get_post_meta($id, '_kksr_casts', true ); 
    	$sumstar = get_post_meta($id, '_kksr_ratings', true ); 
    	$star = round($sumstar / $i);
    		
    		$entity['aggregateRating'] = [
    		"@type" => "AggregateRating",
    		"ratingValue" => "$star",
    		"reviewCount" => "$i",
    	];
    	//var_dump($entity);
    	return $entity;	
    }

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Kamal Khan

    (@bhittani)

    I am not aware of RankMath but to get the structured data json, the code at

    $temprend = get_post_meta('kksr_sd');

    Should be

    $temprend = get_post_meta($id, 'kksr_sd', true);

    This way $temprend will have the json as a string.

    Thread Starter drakeman85

    (@drakeman85)

    Awesome. It works ??
    Thank you very much ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘RankMath Issue’ is closed to new replies.