You can’t use the Pods Admin interface for managing Pods that were registered through code, but you can register the whole thing through code.
pods_register_type
will setup the pod itself (you’ll have to define your options through the options array in that third parameter).
pods_register_field
will setup the field for the pod http://pods.io/docs/code/general-functions/pods-register-field/
To setup multiple meta boxes, you can use pods_group_add
to tell it which fields go where. http://pods.io/docs/code/general-functions/pods-group-add/
Also a big caveat to registering fields through code, relationships won’t get/save properly unless they are ‘simple’ and you provide the options manually.
In an upcoming version of Pods, relationships won’t rely on field IDs and will instead rely on field names. That’ll fix that and pods_register_field()
will finally get more documentation and we’ll push it more.
Hi,
OK, thank you for the answer.
But why the code above doesn’t work? I’m OK with not using Pods Admin interface with this but I can’t use any dashboard page when this is in functions.php
of a theme. Always throws the above error… Why?
Try to add this into Twenty Sixteen’s functions.php
file to test:
if ( function_exists( 'pods_register_type' ) ) :
/**
* Testing Pods plugin
*/
function themeslug_pods_register_custom_fields() {
pods_register_type( 'post_type', 'themeslug_page' );
} // themeslug_pods_register_custom_fields
add_action( 'init', 'themeslug_pods_register_custom_fields' );
endif;
I’m using WordPress multisite. Could this be related to the issue?
Thanks and regards,
Oliver
BTW, like I’ve said I’ve stripped this to pure pods_register_type( 'post_type', 'themeslug_page' );
. Without the 3rd parameter and without additional pods_register_field
to debug. Even this bare minimal code doesn’t work.
So, I can’t really register this Pod (a simple metabox for custom fields) now? Or what do you mean with your answer?
That should work, however you need to run your function check inside your themeslug_pods_register_custom_fields function because Pods may not have loaded everything up and the function might not exist yet, based on what you sent.
No matter if I add the function check inside, that code doesn’t work. That’s my point.
Sounds like there might be a bug afoot then, would you mind opening up a new bug report at https://github.com/pods-framework/pods/issues/new when you have a moment?
Hi,
Thank you, I’ve submitted the issue on Github. For reference: https://github.com/pods-framework/pods/issues/3416
Regards,
Oliver