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 :: dull or blur a background image in react native 
Javascript :: javascript date validation less than today 
Javascript :: document.queryselector picks first or last 
Javascript :: react redux thunk 
Javascript :: check if element with class has another class javascript 
Javascript :: adding a if stement in jsx 
Javascript :: jest mock method by name 
Javascript :: javasciprt set cookie 
Javascript :: instanceof javascript 
Javascript :: how to target checkbox in jquery 
Javascript :: accessing nested objects in javascript 
Javascript :: js convert obj to array 
Javascript :: what is asynchronous 
Javascript :: Generate a Random Integer 
Javascript :: javascript Create Strings 
Javascript :: regex date checker 
Javascript :: convert a string array into object using kerys 
Javascript :: run for loop every second js 
Javascript :: react tailwind loading 
Javascript :: window.location.origin 
Javascript :: component will unmount 
Javascript :: inheritance in class in js 
Javascript :: capitalize first letter in array of strings javascript 
Javascript :: service worker registration 
Javascript :: javascript object get value by key 
Javascript :: split in javascript 
Javascript :: js reduce example 
Javascript :: map javascript 
Javascript :: name first letter uppercase 
Javascript :: parseint function javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =