• Resolved sebzu31

    (@sebzu31)


    Hello!

    i exported the pods configurations from page #1 to a json file. Now I would like to import this file on page #2 using the file functions.php in my theme.

    i tried to use:

    function import_pods_package() {
    	$file = get_template_directory_uri().'/general.json';
    	$json = file_get_contents( $file );
    	$data = json_decode( $json, true );
    
    	if ( ! empty( $data ) && is_array( $data ) ) {
    	  foreach ( $data as $pod_data ) {
    	  pods_api()->import( $pod_data );
    	  }
    	}
    }
    
    import_pods_package();
    

    Warning: Invalid argument supplied for foreach() in C:\laragon\www\wordpress\test\wordpress\wp-content\plugins\pods\classes\PodsAPI.php on line 10668

    this is result πŸ™
    If I have provided too little information, please let me know what else is needed

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

    (@sc0ttkclark)

    I’m not sure I can answer this without confirmation what exactly is in general.json

    However, the good news is that there are far better ways to work with configurations in Pods now. You don’t need to use package imports through code which can be confusing and you have to manage your own logic on when they should run (or if they’ve already run).

    Check out https://docs.pods.io/code/registering-configurations/ for more details about how that works.

    You can also use this function if you want to pass a custom JSON file in a custom place: pods_register_config_file( 'path/to/your/package.json' )

    If you want to use the new configuration detection logic, you can specify a path and Pods will attempt to look for configurations (as documented on that doc page) in their respective locations: pods_register_config_path( 'path/to/your/packages/' )

    Plugin Author Jory Hogeveen

    (@keraweb)

    Closing issue due to inactivity

    Thread Starter sebzu31

    (@sebzu31)

    Thank you for your response, and I apologize for my delay.

    Importing is working correctly, but I am unable to modify any fields. I receive the following error message:

    “Error: [POD NAME] not saved.”

    Additionally, in the Pods management panel, I can only duplicate the pods, and the options to edit or delete them are missing.

    If you need the JSON file to help me, please let me know, and I will provide a link to the file (it’s too long to paste here).

    Plugin Author Jory Hogeveen

    (@keraweb)

    Did you try to fix the fields using Pods > Settings? It could be that this config file is from an older version.

    Cheers, Jory

    Thread Starter sebzu31

    (@sebzu31)

    – Both services have the latest version of the Pods framework.
    – I tried to fix fields as you said but select field is empty (emptyselect.jpg)

    It’s interesting that some changes can be seen on the website in some fields despite incorrect saving (changes are not visible in the admin panel and default values remain).

    I’m attaching a link to 2 screenshots for reference and a json file. I’m counting on your help:

    https://we.tl/t-6iyZLobe8m




    Thread Starter sebzu31

    (@sebzu31)

    I don’t want to rush, but I would like to ask for help again in solving the problem.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @sebzu31

    Thanks for the screenshots, these help.

    In the post-list.jpg screenshot I can see that all of your pods are loaded from a theme file. That is the reason you cannot edit them.

    There is also one Pod that isn’t installed correctly. This is most likely due to an error in your json file or because there is a conflict with the theme or one of your plugins.
    This Pod is the 0 you see in the emptyselect.jpg dropdown. You could try to select that and run the repair tool.

    Cheers, Jory

    Thread Starter sebzu31

    (@sebzu31)

    Mhmm, as always, thank you for your response. I admit that at first I was thrilled with how easy it is to work with your plugin. Everything was going well until this problem. I haven’t been able to solve it for a while and I’m counting on your help. It’s always good to hear a new idea, but unfortunately in this case, the solution from your previous answer didn’t help (fixing field 0 returns “No Pod selected.”). Maybe it will be easier if I explain more clearly what exactly effect I want to achieve:

    Is there a function that, when the theme is enabled that will create fields in the database allowing the user to edit them? Currently, my theme requires the installation of the Pods Framework plugin, and I would like to make the first launch as easy as possible for the end user (not everyone will be thrilled about manually importing a file in the Pods panel).
    If this is a “common” issue, please forgive me, but I haven’t found any information in the documentation.

    Thank you for taking the time to help me with this problem. This issue has been causing me a lot of frustration, and you are my last hope :D.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @sebzu31

    To be honest I’m not that familiar with theme config files for Pods yet as it is a quite new feature.

    If you want it all registered from the theme then it’s best not to work with package imports but to try and combine your modifications into the theme JSON file.

    You could also create a new staging site and register the full config manually, then export this config and paste the code in your theme JSON file. This might be a simpler way to make adjustments for your theme.

    Combining imports with theme files is possible but you need to make sure there aren’t any overlapping Pod names as this will result in errors.

    It could of course be that I’m totally misunderstanding the issue, if so, please let me know.

    Cheers, Jory

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Importing pods with php’ is closed to new replies.