Support

Account

Home Forums Backend Issues (wp-admin) ACF field value from query string

Solved

ACF field value from query string

  • I have custom fields setup for my products post type. In the backend on new product page, I would like to populate a field from the value in a query string in the URL. I am using a custom admin menu with custom links. What is the code thats needed to set a custom field value based on the value of the query string.

    I know how $_GET works, I just need to know the custom function to store the value of the query string to the custom field.

    Thanks!

  • I have made it work. See my example code:

    add_filter('acf/load_value/name=product_type', 'my_acf_load_value', 10, 3);
    function my_acf_load_value( $field ) {
    	if (isset($_GET['product_type'])) {
        $product_type = $_GET['product_type'];
        $field = $product_type;
      }
      return $field;
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF field value from query string’ is closed to new replies.