Frontend unique for post type
-
I’m not sure why I’m having this problem, but for some reason I’m able to enter duplicate values on the frontend of my site. It works fine in the admin panel, but doesn’t work on the front end for some reason.
I have the frontend validation checked in the settings, but it’s just not working.
Here is my code:
functions.phpfunction my_pre_save_post( $post_id ) { if ( $post_id != 'new' ) { return $post_id; } if ( current_user_can('publish_posts') ) { $post = array( 'post_status' => 'publish', 'post_title' => $_POST['fields']['field_5458997dcb49c'], 'post_type' => 'videos' ); $post_id = wp_insert_post($post); $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] ); return $post_id; } else { $post = array( 'post_status' => 'pending', 'post_title' => $_POST['fields']['field_5458997dcb49c'], 'post_type' => 'videos' ); $post_id = wp_insert_post($post); $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] ); return $post_id; } } add_filter('acf/pre_save_post' , 'my_pre_save_post' );theme template file
<?php if ( is_user_logged_in() ) { ?> <?php while ( have_posts() ) : the_post(); ?> <?php acf_form(array( 'post_id' => 'new', 'field_groups' => array(8), 'new_post' => array( 'post_type' => 'videos', 'post_status' => 'publish' ), 'submit_value' => 'Share Video' )); ?> <?php endwhile; ?> <?php } else { ?> <p>You must be logged in to view this page!</p> <?php } ?>
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
The topic ‘Frontend unique for post type’ is closed to new replies.