Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- when specific value is set then it will set that's meta_value
- suppose value="1"
- // here meta_value has been set up 1
- like
- <input type="checkbox" id="myText" class="regular-text" name="myText" value="1" <?php if(get_post_meta($post->ID, 'myText', true)):?> checked <?php endif;?>>
- if meta value suppose in <input >
- value not set OR set
- like
- <input type="checkbox" id="myText" class="regular-text" name="myText" <?php if(get_post_meta($post->ID, 'myText', true)):?> checked <?php endif;?>>
- then value set auto meta_value "on"
- */
- /**
- * Register meta box(es).
- */
- function wpdocs_register_meta_boxes() {
- add_meta_box(
- 'meta-box-id', // uniqueue id
- __( 'Featured Posts','customquery' ), // Title name and textdomain
- 'wpdocs_my_display_callback', // callback function
- array(
- 'post'
- ) // post type
- );
- }
- add_action( 'add_meta_boxes', 'wpdocs_register_meta_boxes' );
- /**
- * Meta box display callback.
- *
- * @param WP_Post $post Current post object.
- */
- function wpdocs_my_display_callback( $post ) {
- // Display code/markup goes here. Don't forget to include nonces!
- ?>
- <label for="myText"><?php _e("Show Your Post As Featured Post","customquery");?><label/>
- <input type="checkbox" id="myText" class="regular-text" name="myText" value="1" <?php if(get_post_meta($post->ID, 'myText', true)):?> checked <?php endif;?>>
- <?php
- }
- /**
- * Save meta box content.
- *
- * @param int $post_id Post ID
- */
- function wpdocs_save_meta_box( $post_id ) {
- // Save logic goes here. Don't forget to include nonce checks!
- if(isset($_POST["myText"])){
- update_post_meta($post_id, 'myText', sanitize_text_field($_POST['myText']) );
- }
- }
- add_action( 'save_post', 'wpdocs_save_meta_box' );
- // Show / display this data anywehere you need/want
- //echo get_post_meta($post->ID, 'myText', true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement