Support

Account

Home Forums Front-end Issues Unique value field Reply To: Unique value field

  • As the writer of the original code, I’ve never tried it on a front end post.

    If the form is editing and existing post then a post ID should be set and the code should work.

    However, if this is for creating a new post, as @howdy_mcgee says, you’ll have issues.
    1) You can’t check for it

    2) Using a made up post ID will not work since the code requires the post_type and with a made up ID or an id of ‘new_?’ get_post_type() will return false.

    In the case of #2,
    1) you need to forget about checking to see if the post id is set and just remove that code.
    2) You need to hard code the post type(s) to check and not rely on get_post_type()
    3) You need to remove the 'post__not_in' => array($post_id), portion of the query since being a new post you don’t need to worry about the current post returning a false positive.