PHP code example of arraypress / wp-register-fields

1. Go to this page and download the library: Download arraypress/wp-register-fields library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arraypress / wp-register-fields example snippets


add_action( 'init', function () {
    register_post_fields( 'product_info', [
        'title'      => __( 'Product Information', 'textdomain' ),
        'post_types' => 'product',
        'fields'     => [
            'sku'   => [
                'label' => __( 'SKU', 'textdomain' ),
                'type'  => 'text',
            ],
            'price' => [
                'label' => __( 'Price', 'textdomain' ),
                'type'  => 'number',
                'min'   => 0,
                'step'  => 0.01,
            ],
        ],
    ] );
} );

// Reading it back.
$sku = get_post_field_value( $post_id, 'sku' );

register_term_fields( 'category', [ /* ... */ ] );
register_user_fields( [ /* ... */ ] );
register_quick_edit_fields( 'product', [ /* ... */ ] );
register_bulk_edit_fields( 'product', [ /* ... */ ] );

// And read back the same way.
$colour = get_term_field_value( $term_id, 'colour' );
$phone  = get_user_field_value( $user_id, 'phone' );
$fields = get_term_fields( 'category' ); // The registered set, for get_value() and friends.