Support

Account

Home Forums General Issues How to populate a field with a $_GET ?

Solved

How to populate a field with a $_GET ?

  • Hello, I am going to try to be simplier since no answer to my last message.
    OK, I have this in my url:

    http://url/page/?id=12345

    page is a wordpress page done as described in ACF’s documentation.

    acf_form_head();
    get_header(); 
    the_post(); 
    ?>
    <section id="primary" class="content-area">
        <div id="content" class="site-content" role="main">
        <?php 
        $args = array(
    	'post_id' => 'new_post',
    	'post_title' => 'true',
    	'field_groups' => array( 39, 20 ),
    	'new_post'	=> array(
         	                         'post_type'=> 'post',
    				 'post_status'=> 'draft'
    				),
    	'submit_value'	=> "Creer ce nouvel article"
    	);
    	acf_form( $args ); 
        ?>
       </div><!-- #content -->
    </div><!-- #primary -->
    
    <?php 
    get_sidebar();
    get_footer();

    So, $_GET[‘id’] = 12345, and I would like to see 12345 populating number 39 declared in field_group !

    How do I have to do ?

    I precise I am trying to create a new post.

    Thanks for your help.

  • Easy !

    function my_acf_load_value( $value, $post_id, $field )
    {
        return $_GET['id'];
    }
    add_filter('acf/load_value/key=field_547ccecd7b091', 'my_acf_load_value', 10, 3);

    I dont know why 10 and 3, it is in the documentation.

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

The topic ‘How to populate a field with a $_GET ?’ is closed to new replies.