PHP code example of underpin / meta-loader

1. Go to this page and download the library: Download underpin/meta-loader 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/ */

    

underpin / meta-loader example snippets


// Register meta record type
underpin()->meta()->add( 'example-meta-field', [
	'key'           => 'unique_meta_key',
	'description'   => 'Description of the purpose of this field',
	'name'          => 'Human-readable name',
	'default_value' => false,
	'type'          => 'post', // Metadata type. Can be post or user, or any custom meta type.
] );

underpin()->meta()->add('meta-record-type-key','Namespace\To\Class');

// Fetch from global context
$object_id = 1;
underpin()->meta()->get_meta( 'example-meta-field',$object_id );

// Fetch, given a meta factory
$meta = underpin()->meta()->get('example-meta-field');
$object_id = 1;

$meta->get( $object_id );

// Fetch all registered user meta

// Filter the registry for user meta fields.
$registered_user_meta = underpin()->meta()->filter(['type' => 'user']);
$values = [];
$user_id = 1;

foreach($registered_user_meta as $object){
  $values[underpin()->meta()->get_key($object)] = $object->get( $user_id );    
}

// Fetch all registered post meta
// Filter the registry for post meta fields.
$registered_user_meta = underpin()->meta()->filter(['type' => 'post']);
$post_id = 1;

foreach($registered_user_meta as $object){
  $object->reset( $post_id );    
}