Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

property of non-object WordPress

  • SOLVED

Hello,

A somewhat similar question to previous questions of mine here at WP Questions.
Explanations there didn't gave me the exact result to fix things here I'm afraid, and therefore yet another 'Undefined' notice related question (:

I am aware these notices cant really do any harm. Also, I am aware of both

define('WP_DEBUG', false);

and

error_reporting(E_ERROR);

It's sort of I biggy, but I believe this would be the part that matters

public function wp_insert_post() {
global $wpdb;
global $post;
global $enquete_table_name;
if ($post->post_type == 'enquete') { // line 156
$check = "SELECT COUNT(ID) AS num FROM `$enquete_table_name` WHERE ID = " . $post->ID;
$res = $wpdb->get_results($check);
if ($res[0]->num == 0) {
$query = "
INSERT INTO `$enquete_table_name`
VALUES(
" . $post->ID . ",
'" . $_POST['post_title'] . "',
'" . $_POST['wp_enquete_answer'][0] . "',
'" . $_POST['wp_enquete_answer'][1] . "',
NOW()
)
";
} else {
$query = "
UPDATE `$enquete_table_name`
SET
question = '" . $_POST['post_title'] . "',
a1 = '" . $_POST['wp_enquete_answer'][0] . "',
a2 = '" . $_POST['wp_enquete_answer'][1] . "',
WHERE ID = " . $post->ID;
}
$wpdb->query($query);
update_post_meta($post->ID, 'show_answers', $_POST['wp_enquete_answer_show']);
}
}


Notice: Trying to get property of non-object in /home/design24/public_html/klanten/23/wp-content/plugins/wp-enquete/enquete.class.php on line 156

This would be the complete code
http://pastebin.com/4gQZvFLg
http://pastebin.com/JuduP94V

PS. If you'd see any other weird behavior in the rest of the code, and would like to comment on that, you probably would be my favorite hero as now now (:

Answers (2)

2011-06-15

Jarret Minkler answers:

if ($post->post_type == 'enquete') {

This means that $post is not an object, so, post_type (a property of the object) cannot be found.

You have to check if post is valid first with somehting like

if($post && $post->post_type && $post->post_type == 'enquete') {

And since you are not getting $post as a post, you may want to investigate why you are not setting global $post to a post.

2011-06-15

Just Me answers:

What is the output of "print_r($post);" after the "global $post;" declaration?