# Nuevo campo para ordenar
function pampa_quickedit_custom_posts_columns( $posts_columns ) {
$posts_columns['pampa_orden'] = __( 'Orden', 'pampa' );
return $posts_columns;
}
add_filter( 'manage_portfolio_posts_columns', 'pampa_quickedit_custom_posts_columns' );
# Visibilidad de columna en el backend
function pampa_quickedit_custom_column_display( $column_name, $post_id ) {
if ( 'pampa_orden' == $column_name ) {
$pampa_orden = get_post_meta( $post_id, 'pampa_orden', true );
if ( $pampa_orden ) {
echo esc_html( $pampa_orden );
} else {
esc_html_e( 'N/D', 'pampa' );
}
}
}
add_action( 'manage_portfolio_posts_custom_column', 'pampa_quickedit_custom_column_display', 10, 2 );
# Visibilidad en Edición Rápida
function pampa_quickedit_fields( $column_name, $post_type ) {
if ( 'pampa_orden' != $column_name )
return;
$pampa_orden = get_post_meta( $post_id, 'pampa_orden', true );
?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<label>
<span class="title"><?php esc_html_e( 'Orden', 'pampa' ); ?></span>
<span class="input-text-wrap">
<input type="number" min="1" name="pampa_orden" class="pampaOrden" value="" style="width: auto; margin-left: -31px;">
</span>
</label>
</div>
</fieldset>
<?php
}
add_action( 'quick_edit_custom_box', 'pampa_quickedit_fields', 10, 2 );
# Almacenar datos en la base de datos
function pampa_quickedit_save_post( $post_id, $post ) {
// if called by autosave, then bail here
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// if this "post" post type?
if ( $post->post_type != 'portfolio' )
return;
// does this user have permissions?
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
// update!
if ( isset( $_POST['pampa_orden'] ) ) {
update_post_meta( $post_id, 'pampa_orden', $_POST['pampa_orden'] );
}
}
add_action( 'save_post', 'pampa_quickedit_save_post', 10, 2 );
# Cargar el valor del campo en la edición rápida
function pampa_quickedit_javascript() {
$current_screen = get_current_screen();
if ( $current_screen->id != 'edit-portfolio' || $current_screen->post_type != 'portfolio' )
return;
// Ensure jQuery library loads
wp_enqueue_script( 'jquery' );
?>
<script type="text/javascript">
jQuery( function( $ ) {
$( '#the-list' ).on( 'click', 'button.editinline', function( e ) {
e.preventDefault();
var pampaOrden = $(this).data( 'pampa-orden' );
inlineEditPost.revert();
$( '.pampaOrden' ).val( pampaOrden ? pampaOrden : '' );
});
});
</script>
<?php
}
add_action( 'admin_print_footer_scripts-edit.php', 'pampa_quickedit_javascript' );
function pampa_quickedit_set_data( $actions, $post ) {
$found_value = get_post_meta( $post->ID, 'pampa_orden', true );
if ( $found_value ) {
if ( isset( $actions['inline hide-if-no-js'] ) ) {
$new_attribute = sprintf( 'data-pampa-orden="%s"', esc_attr( $found_value ) );
$actions['inline hide-if-no-js'] = str_replace( 'class=', "$new_attribute class=", $actions['inline hide-if-no-js'] );
}
}
return $actions;
}
add_filter('post_row_actions', 'pampa_quickedit_set_data', 10, 2);
function pampa_quickedit_custom_posts_columns( $posts_columns ) {
$posts_columns['pampa_orden'] = __( 'Orden', 'pampa' );
return $posts_columns;
}
add_filter( 'manage_portfolio_posts_columns', 'pampa_quickedit_custom_posts_columns' );
# Visibilidad de columna en el backend
function pampa_quickedit_custom_column_display( $column_name, $post_id ) {
if ( 'pampa_orden' == $column_name ) {
$pampa_orden = get_post_meta( $post_id, 'pampa_orden', true );
if ( $pampa_orden ) {
echo esc_html( $pampa_orden );
} else {
esc_html_e( 'N/D', 'pampa' );
}
}
}
add_action( 'manage_portfolio_posts_custom_column', 'pampa_quickedit_custom_column_display', 10, 2 );
# Visibilidad en Edición Rápida
function pampa_quickedit_fields( $column_name, $post_type ) {
if ( 'pampa_orden' != $column_name )
return;
$pampa_orden = get_post_meta( $post_id, 'pampa_orden', true );
?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<label>
<span class="title"><?php esc_html_e( 'Orden', 'pampa' ); ?></span>
<span class="input-text-wrap">
<input type="number" min="1" name="pampa_orden" class="pampaOrden" value="" style="width: auto; margin-left: -31px;">
</span>
</label>
</div>
</fieldset>
<?php
}
add_action( 'quick_edit_custom_box', 'pampa_quickedit_fields', 10, 2 );
# Almacenar datos en la base de datos
function pampa_quickedit_save_post( $post_id, $post ) {
// if called by autosave, then bail here
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// if this "post" post type?
if ( $post->post_type != 'portfolio' )
return;
// does this user have permissions?
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
// update!
if ( isset( $_POST['pampa_orden'] ) ) {
update_post_meta( $post_id, 'pampa_orden', $_POST['pampa_orden'] );
}
}
add_action( 'save_post', 'pampa_quickedit_save_post', 10, 2 );
# Cargar el valor del campo en la edición rápida
function pampa_quickedit_javascript() {
$current_screen = get_current_screen();
if ( $current_screen->id != 'edit-portfolio' || $current_screen->post_type != 'portfolio' )
return;
// Ensure jQuery library loads
wp_enqueue_script( 'jquery' );
?>
<script type="text/javascript">
jQuery( function( $ ) {
$( '#the-list' ).on( 'click', 'button.editinline', function( e ) {
e.preventDefault();
var pampaOrden = $(this).data( 'pampa-orden' );
inlineEditPost.revert();
$( '.pampaOrden' ).val( pampaOrden ? pampaOrden : '' );
});
});
</script>
<?php
}
add_action( 'admin_print_footer_scripts-edit.php', 'pampa_quickedit_javascript' );
function pampa_quickedit_set_data( $actions, $post ) {
$found_value = get_post_meta( $post->ID, 'pampa_orden', true );
if ( $found_value ) {
if ( isset( $actions['inline hide-if-no-js'] ) ) {
$new_attribute = sprintf( 'data-pampa-orden="%s"', esc_attr( $found_value ) );
$actions['inline hide-if-no-js'] = str_replace( 'class=', "$new_attribute class=", $actions['inline hide-if-no-js'] );
}
}
return $actions;
}
add_filter('post_row_actions', 'pampa_quickedit_set_data', 10, 2);