Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: widgets
- Version: 1.0
- Plugin URI:
- Description: Create widgets
- Author: RBS
- Author URI:
- License: GPLv2 or later
- License URI: http://www.opensource.org/licenses/gpl-license.php
- */
- //Uson una CPT llamada 'curso-ingles-basico'
- add_action( 'add_meta_boxes', 'rb_mp3tables_register_meta_boxes' );
- function rb_mp3tables_register_meta_boxes(){
- add_meta_box( 'rb_mp3tables_1', 'Mp3 Tables', 'rb_mp3tables_1_display', 'curso-ingles-basico', 'advanced', 'high');
- add_meta_box( 'rb_podcastfields_id1', 'Podcast Fields', 'rb_podcastfields_id1_display', 'curso-ingles-basico','side', 'high' );
- }
- // METABOX1
- // Añadimos los campos de formulario a nuestro meta box
- function rb_mp3tables_1_display( $post ){
- $post_id = $post->ID;
- //obtenemos los metadata de este post
- $rb_mp3tables_metadata = get_post_meta( $post_id, '_rb_mp3tables_folder', true );
- ?>
- <!-- text -->
- <p>
- <label for="rb_mp3tables_folder">Folder:</label>
- <input type="text" name="rb_mp3tables_folder" id="rb_mp3tables_folder" value="<?php if( isset( $rb_mp3tables_metadata ) ) echo $rb_mp3tables_metadata; ?>">
- </p>
- <?php
- }
- // METABOX2 - Busca los post ID del CPT 'podcast' que está generado por Simple Seriously Podcasting
- // Añadimos los campos de formulario a nuestro meta box
- function rb_podcastfields_id1_display($post){
- $post_id = $post->ID;
- $rb_podcast_enabled = get_post_meta( $post_id, '_rb_podcast_enabled', true );
- $rb_podcast_episode = get_post_meta( $post_id, '_rb_podcast_episode', true );
- ?>
- <p>
- <label for="rb_podcast_enabled">
- <input type="checkbox" name="rb_podcast_enabled" id="rb_podcast_enabled" value="yes" <?php if( isset( $rb_podcast_enabled ) ) checked($rb_podcast_enabled, 'yes'); ?>>
- Podcast Enabled?</label>
- </p>
- <?php
- $args = array( 'posts_per_page' => 100,
- 'offset' => 0,
- 'category' => '',
- 'category_name' => '',
- 'orderby' => 'date',
- 'order' => 'desc',
- 'post_type' => 'podcast',
- 'post_parent' => '',
- 'post_status' => 'publish',
- 'suppress_filters' => true );
- $my_query = new WP_Query( $args );
- ?>
- <p>
- <label for="rb_podcast_episode">Podcast Episode</label>
- <select name="rb_podcast_episode" id="rb_podcast_episode">
- <option value="">-- Choose Podcast</option>
- <?php
- if ($my_query->have_posts()) : while( $my_query->have_posts() ): $my_query->the_post(); ?>
- <option value ="<?php the_ID(); ?>" <?php if( isset( $rb_podcast_episode ) ) selected($rb_podcast_episode, get_the_ID() ); ?>> <?php the_title(); ?> </option>
- <?php endwhile; wp_reset_postdata(); endif; ?>
- </select>
- </p>
- <?php
- }
- // Guardamos los meta datos
- add_action( 'save_post', 'rb_mp3tables_save_meta' );
- function rb_mp3tables_save_meta( $post_id ){
- // comprobamos si hay datos en el campo del formulario
- if( isset($_POST['rb_mp3tables_folder']) && ($_POST['rb_mp3tables_folder'] != '') ):
- // añadirlo o modificar el metadata
- update_post_meta( $post_id, '_rb_mp3tables_folder', $_POST['rb_mp3tables_folder'] );
- endif;
- // comprobamos si hay datos en el campo del formulario
- if( isset($_POST['rb_podcast_enabled']) && ($_POST['rb_podcast_enabled'] !='')):
- // añadirlo o modificar el metadata
- update_post_meta( $post_id, '_rb_podcast_enabled', $_POST['rb_podcast_enabled'] );
- endif;
- if( isset($_POST['rb_podcast_episode']) && ($_POST['rb_podcast_episode'] !='')):
- // añadirlo o modificar el metadata
- update_post_meta( $post_id, '_rb_podcast_episode', $_POST['rb_podcast_episode'] );
- endif;
- }
Advertisement
Add Comment
Please, Sign In to add comment