Import custom fields via plugin
-
Thanks for this incredibly useful plugin!
I have been reading through everything I can find on how to import custom fields via a plugin and so far have not had much luck. I haven’t done a lot of plugin development, though, so I’m probably just missing something about how the CFS works. Here’s what I’ve done so far:
1. Built out my custom fields in a dev environment and exported them
2. Added them to a text file
3. First activated CFS, then tried to activate my pluginHere’s my code:
global $cfs; $content = file_get_contents( plugin_dir_path( __FILE__ ) . '/custom-meta/custom-meta-fields.txt', true); $meta = json_decode( $content, true ); $options = array( 'import_code' => $meta ); $cfs->field_group->import( $options );When I activate the plugin, I get the notice “Trying to get property of non-object” on the line $cfs->field_group->import( $options );
The JSON is valid and I’m using PHP 5.5. Based on some trial and error, I’m wondering if the problem is with trying to access CFS from inside another plugin rather than with my exported fields. Any pointers or suggestions would be much appreciated!
The topic ‘Import custom fields via plugin’ is closed to new replies.