Action ‘save_post’ not working for quick edit

It’s just a guess, since I haven’t tested your code, but… There is a part that looks pretty sketchy for me:

All your actions are run only if this condition is true:

if(isset($post_type) && $post_type == "listings"){

And where that $post_type variable comes from?

$post_type = get_post_type();

So you don’t pass any post_id to that function call… This means that you work with global $post object. But there is no guarantee that such posts exists.

There is a reason why save_post hook passes post_id as param – you should use it inside your function…

So changing the line above to:

$post_type = get_post_type($post_id);

should solve your problem.

PS. There’s no point in doing that:

$post_types = get_post_types();

unset($post_types['listings']);

You don’t even use that variable in your code later on…

PPS. save_post is an action, so you don’t have to return anything in it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)