ID, '_portada', true) ? 'checked="checked"' : ''; echo ''; } add_action('save_post', 'save_checkbox_portada'); function save_checkbox_portada($post_id){ // Si la llamada es un autosave, no queremos hacer nada if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; // Comprobamos los permisos del usuario if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; if ($_POST['es_portada']){ // Si el checkbox está marcado, añadimos el meta key add_post_meta($post_id, '_portada', '1'); }else{ // Si no está marcado, borramos el meta key delete_post_meta($post_id, '_portada'); } } function get_posts_portada(){ $portada = new WP_query('meta_key=_portada'); if (! $portada->have_posts()) { $portada = new WP_query(); } while ( $portada->have_posts() ) : $portada->the_post(); ?>

Leer entrada