Skip to main content
added 174 characters in body
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

Within a function or method, the return statement immediately stops the execution of the earlier.
Hence the last line never gets interpreted.

Switch the order of this:

return $social_score; 
update_post_meta($post_id, '_social_score', $social_score);

to this:

update_post_meta($post_id, '_social_score', $social_score);
return $social_score;

Update:

You are using three different variables for the post id, namely: $post_ID, $post_id and $post->ID. You should use the function argument: $post_ID.

Within a function or method, the return statement immediately stops the execution of the earlier.
Hence the last line never gets interpreted.

Switch the order of this:

return $social_score; 
update_post_meta($post_id, '_social_score', $social_score);

to this:

update_post_meta($post_id, '_social_score', $social_score);
return $social_score;

Within a function or method, the return statement immediately stops the execution of the earlier.
Hence the last line never gets interpreted.

Switch the order of this:

return $social_score; 
update_post_meta($post_id, '_social_score', $social_score);

to this:

update_post_meta($post_id, '_social_score', $social_score);
return $social_score;

Update:

You are using three different variables for the post id, namely: $post_ID, $post_id and $post->ID. You should use the function argument: $post_ID.

added 48 characters in body
Source Link
Johannes Pille
  • 11.1k
  • 3
  • 42
  • 53

The problem might be that you are returningWithin a function or method, the value beforereturn statement immediately stops the update, iexecution of the earlier.e
Hence the last line never gets interpreted. you have these lines in your code example

Switch the order of this:

return $social_score; 
update_post_meta($post_id, '_social_score', $social_score);

Tryto this instead:

update_post_meta($post_id, '_social_score', $social_score);
return $social_score;

The problem might be that you are returning the value before the update, i.e. you have these lines in your code example:

return $social_score; 
update_post_meta($post_id, '_social_score', $social_score);

Try this instead:

update_post_meta($post_id, '_social_score', $social_score);
return $social_score;

Within a function or method, the return statement immediately stops the execution of the earlier.
Hence the last line never gets interpreted.

Switch the order of this:

return $social_score; 
update_post_meta($post_id, '_social_score', $social_score);

to this:

update_post_meta($post_id, '_social_score', $social_score);
return $social_score;
Source Link
birgire
  • 67.8k
  • 7
  • 119
  • 251

The problem might be that you are returning the value before the update, i.e. you have these lines in your code example:

return $social_score; 
update_post_meta($post_id, '_social_score', $social_score);

Try this instead:

update_post_meta($post_id, '_social_score', $social_score);
return $social_score;