• Hi guys,

    Sorry if this question was already answered.

    I am trying to add a Pod and some custom fields via my theme’s functions.php file. I’ve created this function:

    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' );
    

    As you can see, I’ve stripped this down to bare minimum but it still throws me an error in WP dashboard: http://easycaptures.com/fs/uploaded/848/1822267647.png

    I’ve tried disabling all the other plugins but this didn’t help.

    What I am trying to do is to add a metabox to easily set up custom fields for WordPress Pages. I want this to be automatically added through the theme once a user activates the Pods plugin. But I am stuck in here…

    Could you please help me resolving the issue?

    Thanks in advance!

    Regards,

    Oliver

    https://wordpress.org/plugins/pods/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    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/

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    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.

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    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.

    Thread Starter WebMan Design | Oliver Juhas

    (@webmandesign)

    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

    Thread Starter WebMan Design | Oliver Juhas

    (@webmandesign)

    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.

    Thread Starter WebMan Design | Oliver Juhas

    (@webmandesign)

    So, I can’t really register this Pod (a simple metabox for custom fields) now? Or what do you mean with your answer?

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    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.

    Thread Starter WebMan Design | Oliver Juhas

    (@webmandesign)

    No matter if I add the function check inside, that code doesn’t work. That’s my point.

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    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?

    Thread Starter WebMan Design | Oliver Juhas

    (@webmandesign)

    Hi,

    Thank you, I’ve submitted the issue on Github. For reference: https://github.com/pods-framework/pods/issues/3416

    Regards,

    Oliver

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Error adding a Pod via a theme’ is closed to new replies.