Support

Account

Home Forums General Issues Logic between number and relationship fields Reply To: Logic between number and relationship fields

  • I was able to do it in a static way using some code from another thread here

    My current code looks like this

    
      function load_proper_choices_number ( $field ) {
        global $post;
        if (!$post ||
        		!isset($post->ID) ||
        		( get_post_type($post->ID) != 'featured-content' ) ) {
        				return $field;
        }
    
        $number_value = get_post_meta($post->ID, 'featured_posts_number');
        $field['max'] = $number_value;
    
        return $field;
      }
      add_action( 'acf/load_field/name=featured_posts', 'load_proper_choices_number');
    

    Works properly with a refresh every time I change the number of posts using the Number field, and now I will try to achieve it using some javascript. I do assume updating the data-max attributes of the relationship field should do the job.

    Will let you know.