• Resolved tera33

    (@tera33)


    I learned that I can create my own tables using PODS. (What are Advanced Content Types).

    I want to set it up from function.php or something like that, not from the admin panel.

    I was able to create the table, but what do I do if I want to change the columns?

    Also, if I set it from function.php, I want to make it impossible to change it from the admin screen.

    (like pods_register_type).

    This is my current code.
    Once created, the process is aborted because of an error.

    function create_custom_table_pod()
    {
    	$pod_name = 'my_custom_test';
    
    	$pod = pods_api()->load_pod(array('name' => $pod_name));
    	if ($pod) return;
    
    
    	$params = array(
    		'storage' => 'table', // カスタムテーブルストレージタイプを指定
    		'type' => 'pod', // コンテンツタイプ
    		'name' => $pod_name, // テーブル名
    		'label' => 'My Custom Table',
    		'public'         => '1',
    		'fields' => array(
    			array(
    				'name' => 'field_name',
    				'label' => 'Field Name',
    				'type' => 'text'
    			),
    			// 他のフィールドをここに追加
    		)
    	);
    
    
    
    	// Pod を作成
    	$pod = pods_api()->save_pod($params);
    
    	// Pod が正常に作成されたか確認
    	if (!is_wp_error($pod)) {
    		echo 'Pod created successfully with ID: ' . $pod;
    	} else {
    		echo 'Error creating Pod: ' . $pod->get_error_message();
    	}
    
    	// pods_register_type( $params['type'], $params['name'], $params );
    }
    add_action('init', 'create_custom_table_pod');

    Also, it would be better if it could be used like the wp-mvc plugin.

    https://wpmvc.org/

    My English is poor, so apologies if I’m rude.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support pdclark

    (@pdclark)

    こんにちは @tera33 さん、

    readme.txt に記載されている通り、pods.json ファイルはテーマに追加することができます。また、pods_register_config_path() または pods_register_config_file() でカスタムパスを登録することもできます。ディレクトリではなくファイルを登録する場合の詳細については、#4856 を参照してください。サポートされているすべてのデータ形式について記載されています。

    JSON/YML ファイルを使用してテーマ内で Pods 設定を登録できます。これは pods.jsonpods/pods.jsonpods/templates.json などに保存されています。また、カスタムパスを登録してサードパーティのプラグインもサポートできます。pods_register_config_path( $full_directory_path ) を使用して /pods/ ディレクトリを含む新しいパスを登録し、自動的に取得します。また、pods_register_config_file( $full_file_path, 'json' ) を使用して特定のファイルを登録できます。

    pods.json ファイルは、Pods Admin > Components > Import / Export Packages の管理画面からエクスポートできます。エクスポートでは、この目的のために選択されたフィールドまたはテンプレートのみが含まれる必要があります。これらは異なる .json ファイルに格納されています。

    この方法でテーブル構造が設定されている場合、管理画面からは編集できなくなります。

    Hi @tera33,

    As noted in readme.txt, a pods.json file can be added to the theme or a custom path registered with pods_register_config_path() or pods_register_config_file(). See #4856 for more details if registering a directory rather than a file, for all the data formats supported.

    Register Pods configurations with JSON/YML files in your theme when stored in pods.json, pods/pods.json, pods/templates.json, etc. Custom paths can be registered to support third party plugins as well. Register new paths using pods_register_config_path( $full_directory_path ) that contain a /pods/ directory to automatically pull from or use pods_register_config_file( $full_file_path, 'json' ) to register a specific file.

    A pods.json file can be exported from the admin under Pods Admin > Components > Import / Export Packages. An export should have only fields or templates selected for this purpose, as these are stored in different .json files.

    If table structure is set using this method, it will no longer be editable from the admin screen.

    Thread Starter tera33

    (@tera33)

    @pdclark

    Thank you in Japanese.
    Success.

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

The topic ‘About pods create table’ is closed to new replies.