Comment positionner un champ personnalisé avant l'éditeur
-
-
Cene sera qu'un doublon si l'OPestprêt à abandonner ACFpour uneméta depublication régulière,sinon la solutioniciestjQuery.This will only be a duplicate if the OP is willing drop ACF for a regular post meta, otherwise the solution here is jQuery.
- 0
- 2013-04-04
- brasofilo
-
Non,je ne suispasen mesure de remplacer `ACF`par desméta depublication régulières.Oui,j'ai compris comment yparveniren utilisantjQuery,maisje me demandais s'il y avait unmoyen de lefaireen utilisant uniquementphpet desfonctions wordpressintégrées?No, I'm not able to replace the `ACF` with regular post meta. Yes, I have figured out how to achive this by using jQuery, but I was wondering if there was a way to do it using only php and built in wordpress functions?
- 0
- 2013-04-04
- Cyclonecode
-
3 réponses
- votes
-
- 2013-04-05
Celapeut être résoluen utilisant cebelextrait et le crochet
edit_form_after_title
. Maisje n'aipastesté ce qui sepasse lorsqueplusieursméta-boîtesexistent. Avec un seul champ ACF (position:normal, style:no-metabox
) celafonctionne:add_action( 'edit_form_after_title', 'pre_title_metabox_wpse_94530' ); function pre_title_metabox_wpse_94530() { global $post, $wp_meta_boxes; do_meta_boxes( get_current_screen(), 'normal', $post ); unset( $wp_meta_boxes['post']['normal'] ); }
Et si cela doit être résolu avecjQuery,ajustez
subtitle_text
à votrenom de champ:// Add hook to Edit and New post foreach( array( 'post.php', 'post-new.php' ) as $hook ) add_action( "admin_footer-$hook", 'move_acf_to_title_wpse_94530' ); function move_acf_to_title_wpse_94530() { // Check post type if( 'post' != get_post_type() ) return; ?> <script type="text/javascript"> jQuery(document).ready( function($) { $( '#acf-field-subtitle_text' ).css( 'width', '100%' ); $( '#acf-subtitle_text' ). insertAfter( '#titlewrap' ); }); </script> <?php }
This can be solved using this nice snippet and
edit_form_after_title
hook. But I haven't tested what happens when more than one meta box exists. With a single ACF field (position:normal, style:no-metabox
) it works:add_action( 'edit_form_after_title', 'pre_title_metabox_wpse_94530' ); function pre_title_metabox_wpse_94530() { global $post, $wp_meta_boxes; do_meta_boxes( get_current_screen(), 'normal', $post ); unset( $wp_meta_boxes['post']['normal'] ); }
And if it has to be solved with jQuery, adjust
subtitle_text
to your Field Name:// Add hook to Edit and New post foreach( array( 'post.php', 'post-new.php' ) as $hook ) add_action( "admin_footer-$hook", 'move_acf_to_title_wpse_94530' ); function move_acf_to_title_wpse_94530() { // Check post type if( 'post' != get_post_type() ) return; ?> <script type="text/javascript"> jQuery(document).ready( function($) { $( '#acf-field-subtitle_text' ).css( 'width', '100%' ); $( '#acf-subtitle_text' ). insertAfter( '#titlewrap' ); }); </script> <?php }
-
C'estgénial,exactement ce queje cherchais.Je recommanderais de spécifier de coller ceci dansfunctions.php dans lethèmepour les développeurs WPmoinsexpérimentés,commemoi!Merci d'avoir répondu.This is brilliant, just what I was looking for. I would recommend specifying to paste this into functions.php in the theme for those lesser experienced WP developers, like me! Thanks for the answer.
- 0
- 2017-06-22
- goose
-
Attention - supprimez-le si vouspassez à la versionpro dupluginCela causera desproblèmes!Il ajoutait un deuxièmeformulaire sur lapage d'édition des champs degroupeet rienn'étaitenregistré.Word of caution - remove this if upgrading to the pro version of the plugin. It will cause issues! It was adding a second form on the group fields edit page and nothing was saving.
- 0
- 2017-09-02
- goose
-
- 2013-04-04
J'ai vérifié cela unpeu. J'ai regardé la source ACF. Les champs simples utiliséspar ACF sonttoujours desméta-boîtes. ACF utilise simplement CSSpour lesfaire ressembler à des champsplusgénériques. Ils sonttoujourstraités comme desméta-boîtespar WP (action
do_metaboxes
).Pour ajouter des champs simples à d'autresparties duformulaire d'édition,vous devrez utiliser les hooks appropriés. Plus de crochets sur l'écran d'édition :
add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' ); function myprefix_edit_form_after_title() { echo '<h2>This is edit_form_after_title!</h2>'; } add_action( 'edit_form_after_editor', 'myprefix_edit_form_after_editor' ); function myprefix_edit_form_after_editor() { echo '<h2>This is edit_form_after_editor!</h2>'; } add_action( 'edit_form_advanced', 'myprefix_edit_form_advanced' ); function myprefix_edit_form_advanced() { echo '<h2>This is ye olde edit_form_advanced!</h2>'; }
I've checked into this a bit. I looked at the ACF source. The plain fields that ACF uses are still actually meta boxes. ACF is just using CSS to make them look like more generic fields. They are still being handled as meta boxes by WP (
do_metaboxes
action).To add plain fields to other parts of the edit form, you'll need to use the appropriate hooks. More hooks on the edit screen:
add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' ); function myprefix_edit_form_after_title() { echo '<h2>This is edit_form_after_title!</h2>'; } add_action( 'edit_form_after_editor', 'myprefix_edit_form_after_editor' ); function myprefix_edit_form_after_editor() { echo '<h2>This is edit_form_after_editor!</h2>'; } add_action( 'edit_form_advanced', 'myprefix_edit_form_advanced' ); function myprefix_edit_form_advanced() { echo '<h2>This is ye olde edit_form_advanced!</h2>'; }
-
- 2020-02-04
Merci à @brasofilopour la réponseinitiale.
Jen'avaisbesoin que de déplacer un champ avant le champ de l'éditeur.Au lieu detous les champs supplémentaires.
Voici commentje l'ai résolu:
add_action( 'edit_form_after_title', 'pre_title_metabox_wpse_94530' ); function pre_title_metabox_wpse_94530() { global $post, $wp_meta_boxes; if ($post->post_type == "event"){ // store current fields $tmp_wp_meta_boxes = $wp_meta_boxes; // isolate one field $excerpt = $tmp_wp_meta_boxes['event']['normal']['core']['postexcerpt']; $wp_meta_boxes = ['event'=>['normal'=>['core'=>['postexcerpt'=>$excerpt]]]]; // render isolated field do_meta_boxes( get_current_screen(), 'normal', $post ); // restore field without $wp_meta_boxes = $tmp_wp_meta_boxes; unset( $wp_meta_boxes['event']['normal']['core']['postexcerpt'] ); } }
With thanks to @brasofilo for the initial answer.
I only needed to move one fields before the editor field. Instead of all additional the fields.
This is how i fixed it:
add_action( 'edit_form_after_title', 'pre_title_metabox_wpse_94530' ); function pre_title_metabox_wpse_94530() { global $post, $wp_meta_boxes; if ($post->post_type == "event"){ // store current fields $tmp_wp_meta_boxes = $wp_meta_boxes; // isolate one field $excerpt = $tmp_wp_meta_boxes['event']['normal']['core']['postexcerpt']; $wp_meta_boxes = ['event'=>['normal'=>['core'=>['postexcerpt'=>$excerpt]]]]; // render isolated field do_meta_boxes( get_current_screen(), 'normal', $post ); // restore field without $wp_meta_boxes = $tmp_wp_meta_boxes; unset( $wp_meta_boxes['event']['normal']['core']['postexcerpt'] ); } }
J'aiinstallé
Advanced Custom Fields 4.0.1
et créé unnouveauField group
contenant un seul champ appelépreamble
.Je souhaitepositionner cenouveau champ avant l'éditeur dans l'écran d'édition des articles.Il semble quetous les champspersonnalisés sonttoujours ajoutés après unepublication de champs ordinaires.Une solutionne seraitpas de supprimer les champspersonnalisés créés avec
ACF
et d'utiliser des champspersonnalisés ordinaires.