php - Getting “Object of class WP_Post could not be converted to string” - when it is a string -
i have next code in functions.php, executes script upon publish:
function save_new_post($post_id) { $site_root = '/home/forexmag/public_html/directory2'; $post = get_post($post_id); $title = $post->post_title; $breaking_news = false; $categories = get_the_category($post_id); if (is_array($categories) && !empty($categories)) { foreach ($categories $cat_det) { //this id breaking (bad) news if (5668 == $cat_det->cat_id) { $breaking_news = true; break; } } } $exec_code = "/usr/local/bin/php $site_root /crons/cron_notify.php '$title' $post_id 2 " . intval($breaking_news); exec( $exec_code ); } add_action('draft_to_publish', 'save_new_post', 10, 1);
when publish new post maintain getting next error:
catchable fatal error: object of class wp_post not converted string in /home/forexmag/public_html/wp-content/themes/forex_magnates/functions.php on line 712
this line set $exec_code
var. however, can see, , confirmed via var_dump, $title
variable string. missing?
edit: what's weirder when var_dump $exec_code
, kill script, perfect string:
string(121) "/usr/local/bin/php /home/forexmag/public_html/directory2/crons/cron_notify.php '2011 free forex report' 9934 2 0"
got right reply on wordpress answers. thought should share it:
$post_id
wp_post
object. exec code should using $post_id->id.
function save_new_post($post_id) { print_r($post_id); die();
returns
wp_post object ( [id] => ...
courtesy of vancoder
do notice depends on hook using. e.g if utilize publish_page
integer (this source of confusion)
php wordpress
No comments:
Post a Comment