I use save_post action to save meta field and to check if post title is set. So I check the value returned by empty($post->post_title) but I get true also if I set the title.

| improve this question | | | | |
  • 1
    false should be the right value. empty() returns false when your title is not empty. – Afterlame Jan 15 '15 at 10:53
  • Sorry I wrote wrong, I get true also if the title is not empty. – Giovanni Putignano Jan 15 '15 at 11:53
  • Could you post a little more code? – TheDeadMedic Jan 15 '15 at 16:33

Without knowing the surrounding code, it is hard to tell what the problem might be, but you said you checked the $post variable. Maybe the $post variable is not set properly, the save_post action only gives you the post id:

function get_post_title($post_id) {
  $post = get_post($post_id);

  if (empty($post->post_title)) {
    // No title set, put in your code
add_action('save_post', 'get_post_title');
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.