Yoast SEO
[Plugin: WordPress SEO by Yoast] WP_Error using ct_desc????? (3 posts)

  1. Jeffrey Schutzman
    Posted 4 years ago #

    Most important, thanks for the great plugin and the all the work you put into all the posts about seo!

    Using the latest version of the plugin my site was giving 500 errors. I tracked it down to line 207 in wpseo_functions.php.

    The 'get_the_terms' call returns an array of taxonomy terms indexed by term_id, not 0 based. When the 0 based reference to the term_id is passed into the field function the WP_error happens and caused the 500 error. Changing the function from get_the_terms to wp_get_object_terms seems to fix the problem. If you want to see what is generated i'll be pushing the fix to http://www.sparkle-gear.com for testing.


  2. Jeffrey Schutzman
    Posted 4 years ago #

    This is what the code in my modified function looks like...

    if ( preg_match_all( '/%%ct_desc_([^%]+)?%%/u', $string, $matches, PREG_SET_ORDER ) ) {
    		global $post;
    		foreach ( $matches as $match ) {
    			$terms  = wp_get_object_terms( $post->ID, $match[ 1 ] );
    			if ( !is_wp_error($terms) ) {
    				$replace_with = empty($terms) ? '' :  get_term_field( 'description', $terms[ 0 ]->term_id, $match[ 1 ] );
    				$string = str_replace( $match[ 0 ], $replace_with , $string );
  3. WPUser1234
    Posted 3 years ago #

    thank you for building this - this actually did the trick for me.
    My other workaround was to // $terms and $string and for some reason that seemed to work as well.

    I'm not sure where the problem lies - as some of my attribute items have this issue - but since upgrading woocommerce the new ones seem to have an issue with YOASTS plugin

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Yoast SEO
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic