Home Forums General Issues Autocomplete fields values


Autocomplete fields values

  • Hi, I’m currently workind on a code for a project, I’m a bit noob with PHP but I’m trying to work with the doc and a few PHP lessons.

    Here is what I want to do :

    I got a custom post about a video, the admin register the video url, author, author’s website, author’s facebook, author’sinstagram.

    When he types the name of the author, i want it to be checked, then if the author already exist, then use the previous data used from a past post for this artist to fill the fields website, instagram, facebook etc…

    I think i got the overall idea of how to articulate the code but…

     // If the value auteur_video1 already exist, take auteur_video other fields (website, facebook, instagram) values
     //  and fill the curent post fields with the data. 
      //  I / Check if value already exist 
     $args = array( 
       'post_type' => 'videos',
       'meta_query' => array(
               'key' => 'auteur_video',
               'value' => '111'
       'fields' => 'ids'
     // perform the query
     $vid_query = new WP_Query( $args );
     $vid_ids = $vid_query->posts;
     // do something if the meta-key-value-pair exists in another post
     if ( ! empty( $vid_ids ) ) {
      //  II / If exist then autocomplete the fields 
    function autocomplete_fields { 
    $artistsite = get_field('website_artiste', $post->ID); // get the auteur_vide1 field value
    $artistfb = get_field('facebook_artiste', $post->ID);  // get the auteur_vide1 field value
    $artistinst = get_field('instagram_artiste', $post->ID); // get the auteur_vide1 field value
    function my_acf_update_value( $value, $post_id, $field  ) {	 // Complete the field facebook_artist with the value 
    	// override value 
        $value = "$artistsite";	
    	// return
        return $value;
     add_filter('acf/update_value/name=facebook_artist', 'my_acf_update_value', 10, 3);

    I don’t expect a full answer i know it takes time and i don’t want to wast your time, but little help (link to apprepiate docs etc..) will be great.
    I will update this thread as my work on this goes if it’s ok, In case it could help someone.


  • Hi @warry,

    For this case, I think it will be better if you use post object field instead. You can create a custom post type using CPT UI to make it easier. You can also create some custom fields to create a new author, and use acf/save_post to save it as a custom post.

    Hope this helps 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Autocomplete fields values’ is closed to new replies.