Support

Account

Forum Replies Created

  • It worked great ! Thanks a lot again!

  • Thanks for your answer !

    I tried to use your code but it display an error and I can’t find why :
    Parse error: syntax error, unexpected ‘,’ in /home/guillaummg/www/faview/wp/wp-content/themes/ffaview/functions.php on line 209

    add_filter( 'posts_distinct', 'cf_search_distinct' );
    
    // PREVENT POST THAT ALREADY EXIST
    add_filter('acf/validate_value/name=lien_video', 'validate_lien_video_filter', 10, 4);
    add_filter('acf/load_value/name=hidden_post_id', 'add_post_id_as_value'), 10, 3);
    function add_post_id_as_value($value, $post_id, $field) {
      return $post_id;
    }
    function validate_lien_video_filter($valid, $value, $field, $input) {
    	$post_id_field_key = 'field_569ce8b4cba44';
      if (!$valid || $value == '' || !isset($_POST['acf'][$post_id_field_key])) {
        return $valid;
      }
    	// change the field key below to the field key for your 
    	// hide_post_id_field field
    	$post_id = $_POST['acf'][$post_id_field_key];
      global $post; 
      $args = array(
        'post_type' => 'videos',  // or your post
        'post__not_in' => array($post_id), // do not check this post
        'meta_query' => array(
          array(
            'key' => 'lien_video',
            'value' => $value
          )
        )
      );
      $query = new WP_Query($args);
      if (count($query->posts)) {
        // found at least one post that
        // already has $value
        $valid = 'There is already a post using this video';
      }
      return $valid;
    }
    
    
  • It worked great ! Thanks a lot !
    Here is my code if it can help someone else :

    The name of my field is : lien_video
    Name of my custom posts : videos

    <?php 
    add_filter('acf/validate_value/name=lien_video', 'validate_lien_video_filter', 10, 4);
    
    function validate_lien_video_filter($valid, $value, $field, $input) {
      if (!$valid || $value == '') {
        return $valid;
      }
      // query posts for the same value
      // for more info see
      // http://codex.wordpress.org/Class_Reference/WP_Query
      global $post; 
      $args = array(
        'post_type' => 'videos',  // or your post
        'post__not_in' => array($post->ID), // do not check this post
        'meta_query' => array(
          array(
            'key' => 'lien_video',
            'value' => $value
          )
        )
      );
      $query = new WP_Query($args);
      if (count($query->posts)) {
        // found at least one post that
        // already has $value
        $valid = 'There is already a post using this video';
      }
      return $valid;
    }
    
    ?>
Viewing 3 posts - 1 through 3 (of 3 total)