Home Forums ACF PRO Can i create a custom field with PHP?


Can i create a custom field with PHP?

  • Hello, i want to store a counter in a custom field with PHP.
    I tried this
    But i think it only updates fields that were previously added to a group.
    How can i do this without adding the field to a group?

    Or shall i just create a new group with nothing but the counter field and add it to a random empty page?
    Or maybe use WP built in custom fields? I tried that first but it didn’t save the new field either. I’m so confused.

  • ACF cannot save values to fields that have not been created in a group. ACF also cannot get values from the field. To use fields that do not exist in an ACF field your you need to use standard WP function like add_post_meta(), update_post_meta(), get_post_meta().

  • Alright. Got it. Now I know not to try it.
    I’ll use wp functions.

    I investigated the reason of those not working. I can’t just use those wp functions on an Ajax called plugin. I must create a function and call admin-ajax.php in the js, also there must be an action with the name of the function that needs to run. I’ll try when I get the time I hope it works!

    This is solved.

  • Yes, all ajax requests in WP need to go through admin-ajax.php. the best source of information on ajax in WP is here

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

The topic ‘Can i create a custom field with PHP?’ is closed to new replies.