Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

getting values for metaboxes in wordpress

function wporg_custom_box_html( $post ) {
    $value = get_post_meta( $post->ID, '_wporg_meta_key', true );
    ?>
    <label for="wporg_field">Description for this field</label>
    <select name="wporg_field" id="wporg_field" class="postbox">
        <option value="">Select something...</option>
        <option value="something" <?php selected( $value, 'something' ); ?>>Something</option>
        <option value="else" <?php selected( $value, 'else' ); ?>>Else</option>
    </select>
    <?php
}
Comment

Saving values for metaboxes in wordpress

function wporg_save_postdata( $post_id ) {
    if ( array_key_exists( 'wporg_field', $_POST ) ) {
        update_post_meta(
            $post_id,
            '_wporg_meta_key',
            $_POST['wporg_field']
        );
    }
}
add_action( 'save_post', 'wporg_save_postdata' );
Comment

adding values for metaboxes in wordpress

function wporg_add_custom_box() {
    $screens = [ 'post', 'wporg_cpt' ];
    foreach ( $screens as $screen ) {
        add_meta_box(
            'wporg_box_id',                 // Unique ID
            'Custom Meta Box Title',      // Box title
            'wporg_custom_box_html',  // Content callback, must be of type callable
            $screen                            // Post type
        );
    }
}
add_action( 'add_meta_boxes', 'wporg_add_custom_box' );
Comment

PREVIOUS NEXT
Code Example
Javascript :: Rest and spread operators in ES6 
Javascript :: Key and property shorthand in ES6 
Javascript :: how to change sender name in nodemailer 
Javascript :: how add element at beginning of array in javascript using splice 
Javascript :: angular material primary lighter 
Javascript :: add script tag change on every new page in angular 8 
Javascript :: image opacity reduce js 
Javascript :: let a local variable 
Javascript :: red foreach loop 
Javascript :: GitHub Personal Access Token is not set, neither programmatically, nor using env "GH_TOKEN" electronjs 
Javascript :: maxscript saveMaxFile 
Javascript :: Create an Array of specific length with some value at each index 
Javascript :: javascript loob array 
Javascript :: dollar sign brackets javascript 
Javascript :: react onpaste get value 
Javascript :: convert path string to url encoding javascript 
Javascript :: automatically function run js function on load after some time 
Javascript :: react avoid spreading non-dom props across component 
Javascript :: Refresh a kendo ui widget, when options on AngularJS $scope change 
Javascript :: AJAX XML - update new live data and prevent returning old chache data 
Javascript :: how to get value from select option using input name in jquery 
Javascript :: serve public folder express without file extension 
Javascript :: Spread Syntax for function 
Javascript :: javascript random function 
Javascript :: create model Obejctid mongoose 
Javascript :: how to make a <li when clicked on a button js 
Javascript :: three movimiento js 
Javascript :: set @Output through modalref angular 
Javascript :: my env.local file not working in my react app usind mac 
Javascript :: javascript YUP utilisation to math certain disire in forms 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =