Support

Account

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

Solved

ACF field value from query string

    • amjad

    • May 15, 2019 at 5:27 am

    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!

    • amjad

    • May 16, 2019 at 3:34 am

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.