Author: naveen

i am a wordpress/php developer. completed my bachelors in Bsc-it and Masters in MCA. i have knowledge of some other language also like JAVA , .NET . i can also work in social media tools and API's.

You can find me on:

Add Metabox in wordpress

There are several plugins available in wordpress which helps to add metabox .  It’s a ridiculous  task for worpress programmer to use them as already we have a simple action.

function adding_custom_boxes( $post_type, $post ) {
    add_meta_box( 
        'my-meta-box',
        __( 'My Meta Box' ),
        'render_my_meta_box',
        'post',     // here you can mention your post_type 
               for multiple post type pass array of them  
        'normal',
        'default'
    );
}

// action to add meta box
add_action('add_meta_boxes','adding_custom_boxes',10,2);

//function to add metabox html
function render_my_meta_box(){

}

Once you have metabox in backend, you will need to save metabox data for further retrieval.
You can save metabox data on post save and post update action.

function my_project_save_metabox_data( $post_id ) {
   /*
    *  here you can write your code to save metabox data
    *  you may get it with $_POST['field_name']
    *  you can save it in anywhere or postmeta.  
    */
}
add_action( 'save_post', 'my_project_save_metabox_data' );

Implode and Explode in PHP

We can store multiple value in single variable in two ways.
Either using Array, or comma separated values.

Comma separated: 
$name = 'Alex,Ana,BOB';
Array:  
$name =  array(
    [0] => 'BOB',
    [1] => 'Alex',
    [2] =>  'Ana'
);

To convert array to comma separated value and reverse
we required two function

implode : 
Syntax:  string implode ( string $glue , array $pieces )

$array = array(
    [0] => 'lastname',
    [1] => 'email',
    [2] => 'phone'
);
$comma_separated = implode(",", $array);

result :   will be "lastname,email,phone".
explode : 
Syntax:  array explode (string $delimiter,string $comma_string)

$input2 = "hello,there";
$result = var_dump( explode( ',', $input2 ) );

result : array( 
    [0] => 'hello',
    [1] => 'there'
);

Thanks ……!