我已安装Advanced Custom Fields 4.0.1
并创建了一个新的Field group
包含一个名为preamble
. 我想把这个新字段放在posts编辑屏幕的编辑器之前。似乎所有自定义字段都是在发布普通字段之后添加的。
解决方案不是删除用创建的自定义字段ACF
并使用普通自定义字段。
我已安装Advanced Custom Fields 4.0.1
并创建了一个新的Field group
包含一个名为preamble
. 我想把这个新字段放在posts编辑屏幕的编辑器之前。似乎所有自定义字段都是在发布普通字段之后添加的。
解决方案不是删除用创建的自定义字段ACF
并使用普通自定义字段。
可以使用以下方法解决此问题this nice snippet 和edit_form_after_title
钩但我还没有测试当存在多个元框时会发生什么。使用单个ACF字段(position:normal, style:no-metabox
) 它的工作原理是:
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\'] );
}
如果必须用jQuery解决,请调整subtitle_text
至您的域名:// 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
}
我已经检查过一点了。我查看了ACF来源。ACF使用的普通字段实际上仍然是元框。ACF只是使用CSS使它们看起来更像通用字段。WP仍将其作为元盒处理(do_metaboxes
操作)。
要将普通字段添加到编辑表单的其他部分,需要使用适当的挂钩。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>\';
}
现在ACF提供了一种本地解决方案。您可以设置字段组的位置。默认情况下,它设置为;职位:高(标题后)“”;但您可以在编辑字段组时更改它。
感谢@brasofilo提供了最初的答案。
我只需要在编辑器字段之前移动一个字段。而不是所有其他字段。
我就是这样修复的:
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\'] );
}
}
我已安装Advanced Custom Fields 4.0.1
并创建了一个新的Field group
包含一个名为preamble
. 我想把这个新字段放在posts编辑屏幕的编辑器之前。似乎所有自定义字段都是在发布普通字段之后添加的。
解决方案不是删除用创建的自定义字段ACF
并使用普通自定义字段。
可以使用以下方法解决此问题this nice snippet 和edit_form_after_title
钩但我还没有测试当存在多个元框时会发生什么。使用单个ACF字段(position:normal, style:no-metabox
) 它的工作原理是:
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\'] );
}
如果必须用jQuery解决,请调整subtitle_text
至您的域名:// 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
}
我已经检查过一点了。我查看了ACF来源。ACF使用的普通字段实际上仍然是元框。ACF只是使用CSS使它们看起来更像通用字段。WP仍将其作为元盒处理(do_metaboxes
操作)。
要将普通字段添加到编辑表单的其他部分,需要使用适当的挂钩。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>\';
}
现在ACF提供了一种本地解决方案。您可以设置字段组的位置。默认情况下,它设置为;职位:高(标题后)“”;但您可以在编辑字段组时更改它。
感谢@brasofilo提供了最初的答案。
我只需要在编辑器字段之前移动一个字段。而不是所有其他字段。
我就是这样修复的:
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\'] );
}
}
一切都好吗<我需要wp-list-table 也要显示custom-fields 在每个custom-post 我有,但我不知道如何做到这一点,在这幅图中,它显示了带有字段的表格:Title, Author and Publication Date: 我想要的是能够选择custom-fields 将出现,例如以下示例Title, Carta, Naipe, Author, and Date of Publication: