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 :: javascript get magnitude of number 
Javascript :: see vuex values production console 
Javascript :: load external javascript from console 
Javascript :: prepend option on 2nd index jquery 
Javascript :: trigger modal after some time react js 
Javascript :: axios in functional component 
Javascript :: for in range javascript 
Javascript :: javascript move array element to front 
Javascript :: discord.js remove embed from message 
Javascript :: react native keyboard push view up 
Javascript :: Uncaught SyntaxError: Cannot use import statement outside a module 
Javascript :: Prevent default event behavior 
Javascript :: how to exit node 
Javascript :: indexof javascript duplicate arrays 
Javascript :: js copy values from one array to another node new 
Javascript :: how to disable button in jquery 
Javascript :: javascript catch specific error 
Javascript :: unzip file electronjs 
Javascript :: how to make page scroll to the top jsx 
Javascript :: select parent of element jquery 
Javascript :: post to /wp-json/wp/v2/media 
Javascript :: cors blocking communication 
Javascript :: express js hello world example 
Javascript :: how to change package name in react native 
Javascript :: js sleep 1 sec 
Javascript :: add line number in javascript 
Javascript :: how to know the current route in react class component 
Javascript :: mongodb working with date 
Javascript :: propertyName nuxt auth 
Javascript :: splash screen react native 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =