我正在为自定义帖子类型创建一个元框.有多个字段我想使用wysiwyg编辑器而不是<textarea>.可以在元框中添加多个编辑器吗?
我将衷心感谢您的帮助!
非常感谢.大傻
我试图使用此脚本在我的metaboxes文件中添加变量而不是自定义字段ID
我在redux框架中添加了一些选项,以便更改自定义字段.
<?php
/*global from framework*/
global $redux;
/*custom fields options retrieved from redux framework*/
$custom_videourl = $redux['mytheme_videourl'];
$custom_duration = $redux['mytheme_duration'];
$custom_description = $redux['mytheme_desc'];
$fields = array(
array(
'label' => __( 'MP4/FLV & Youtube Url', 'framework' ),
'desc' => __( 'Here you can add videos with mp4 format', 'framework' ),
'id' => $custom_videourl,
'type' => 'text'
),
array(
'label' => __( 'Video Duration', 'framework' ),
'desc' => __( 'Example: 5:20', 'framework' ),
'id' => $custom_duration,
'type' => 'text' …Run Code Online (Sandbox Code Playgroud) 我想为页面制作这段代码
add_action( 'add_meta_boxes', 'meta_box_video' );
function meta_box_video()
{
add_meta_box( 'video-meta-box-id', 'Video Embed', 'meta_box_callback', 'post', 'normal', 'high' );
}
function meta_box_callback( $post )
{
$values = get_post_custom( $post->ID );
$selected = isset( $values['meta_box_video_embed'] ) ? $values['meta_box_video_embed'][0] : '';
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>
<p>
<label for="meta_box_video_embed"><p>Video Embed</p></label>
<textarea name="meta_box_video_embed" id="meta_box_video_embed" cols="62" rows="5" ><?php echo $selected; ?></textarea>
</p>
<p>Leave it Empty ( if you want to use an image thumbnail ) .</p>
<?php
}
add_action( 'save_post', 'meta_box_video_save' );
function meta_box_video_save( $post_id ) …Run Code Online (Sandbox Code Playgroud) 我试图从Wordpress后端删除自定义字段部分.我想我找到了一个显示自定义字段的函数.该函数位于wp-admin/edit-page-form.php第181行.
do_meta_boxes('page','normal',$post)
Run Code Online (Sandbox Code Playgroud)
当我删除该功能时,Wordpress也不会显示其他框.
如何从Wordpress后端删除特定的框?
按照以下说明操作:http: //www.farinspace.com/multiple-wordpress-wysiwyg-visual-editors/
我的metaboxes中有一些不错的WYSIWYG编辑器
我的标记看起来像:
<div class="sortable">
<div class="sortme">
<?php $mb->the_field('extra_content2'); ?>
<div class="customEditor"><textarea name="<?php $mb->the_name(); ?>"><?php echo wp_richedit_pre($mb->get_the_value()); ?></textarea></div>
</div>
<div class="sortme"
<?php $mb->the_field('extra_content3'); ?>
<div class="customEditor"><textarea name="<?php $mb->the_name(); ?>"><?php echo wp_richedit_pre($mb->get_the_value()); ?></textarea></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
对于包含在div中的textarea,这只是WP_alchemy(也来自farinspace.com)
和告诉tinymce的脚本:
function my_admin_print_footer_scripts()
{
?><script type="text/javascript">/* <![CDATA[ */
jQuery(function($)
{
var i=1;
$('.customEditor textarea').each(function(e)
{
var id = $(this).attr('id');
if (!id)
{
id = 'customEditor-' + i++;
$(this).attr('id',id);
}
tinyMCE.execCommand('mceAddControl', false, id);
});
});
/* ]]> */</script><?php
}
// important: note the …Run Code Online (Sandbox Code Playgroud) 我试图从元框中保存WordPress数据库中的一些数据.
我有一个下拉列表来选择一些选项,我想通过元框保存所选的数据库选项.
但是我在PHP中的保存功能有些困难:
<?php
function add_admin_menu_class_meta_box() {
$pages = array('post', 'portfolio');
foreach( $pages as $page ) {
add_meta_box('custom_element_grid_class','Element grid size', 'custom_element_grid_class_meta_box', $page, 'side', 'high');
}
}
add_action( 'admin_menu', 'add_admin_menu_class_meta_box' );
function custom_element_grid_class_meta_box(){
?>
<label>Choose the size of the element : </label>
<select name="custom_element_grid_class" id="custom_element_grid_class">
<option value="normal" <?php selected( $meta_element_class, 'normal' ); ?>>normal</option>
<option value="square" <?php selected( $meta_element_class, 'square' ); ?>>square</option>
<option value="wide" <?php selected( $meta_element_class, 'wide' ); ?>>wide</option>
<option value="tall" <?php selected( $meta_element_class, 'tall' ); ?>>tall</option>
</select>
<?php
}
add_action('save_post', …Run Code Online (Sandbox Code Playgroud) 我为产品创建了一些自定义元框.
在writepanel-product_data.php中我添加了:
woocommerce_wp_text_input( array( 'id' => 'orario', 'class' => '', 'label' => __('Orario', 'woocommerce') ) );
woocommerce_wp_text_input( array( 'id' => 'luogo_evento', 'class' => '', 'label' => __('Luogo Evento', 'woocommerce') ) );
woocommerce_wp_text_input( array( 'id' => 'indirizzo', 'class' => '', 'label' => __('Indirizzo', 'woocommerce') ) );
woocommerce_wp_text_input( array( 'id' => 'zona', 'class' => '', 'label' => __('Zona', 'woocommerce') ) );
woocommerce_wp_text_input( array( 'id' => 'contatti', 'class' => '', 'label' => __('Contatti', 'woocommerce') ) );
Run Code Online (Sandbox Code Playgroud)
然后在第681行
update_post_meta( $post_id, 'orario', stripslashes( $_POST['orario'] ) …Run Code Online (Sandbox Code Playgroud) 我创建了一个自定义帖子类型,其中包含元数据日期和日期.
自定义帖子类型创建与回调功能 add_events_metaboxes
function event_list_init(){
$labels = array(
'name' => _x( 'Events', 'post type general name' ),
'singular_name' => _x( 'Event', 'post type singular name' ),
'menu_name' => _x( 'Events List', 'admin menu' ),
'name_admin_bar' => _x( 'Events List', 'add new on admin bar' ),
'add_new_item' => __( 'Add New Event' ),
'new_item' => __( 'New Event' ),
'edit_item' => __( 'Edit Event' ),
'view_item' => __( 'View Event' ),
'all_items' => __( 'All Events' ),
'search_items' => __( 'Search …Run Code Online (Sandbox Code Playgroud) 嗨,我想在自定义帖子类型下的自定义设置页面下添加元数据箱.我可以为自定义帖子类型创建元框也可以创建主题选项.但无法找到在自定义设置页面上添加元数据的任何方法.就像我的帖子类型层次结构如下所示:产品 - 所有项目 - 添加项目 - 产品类别 - 产品设置
我想添加元框并在该设置页面上创建一个选项页面.你能指导我完成这个吗?
我一直试图遵循这个要点,但找不到办法. https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/options-and-settings-pages/theme-options-cmb.php
你也可以通过调整key | value操作的代码来告诉我是否可以实现某些目标
$cmb = new_cmb2_box( array(
'id' => $this->metabox_id,
'hookup' => false,
'show_on' => array(
// These are important, don't remove
'key' => 'options-page',
'value' => array( $this->key, )
),
) );
Run Code Online (Sandbox Code Playgroud)
我已经通过此代码创建了设置页面
add_submenu_page('edit.php?post_type=ch_product_showcase', 'Product Showcase Settings', 'Showcase Settings', 'edit_posts', basename(__FILE__), array( $this, 'chProductShowcaseSettingsOptions') );
Run Code Online (Sandbox Code Playgroud) 我很难从自定义帖子类型的metabox中获取值。
这是我在自定义帖子类型中注册metabox的方法:
register_post_type( 'poslovi-newsletter',
array(
'labels' => array(
'name' => __( 'Poslovi newsletter' ),
'hierarchical' => false,
'singular_name' => __( 'Posalji newsletter' )
),
'public' => true,
'exclude_from_search' => true,
'menu_icon' => 'dashicons-email',
'register_meta_box_cb' => 'add_bez_oznaka_text_metabox'
)
);
Run Code Online (Sandbox Code Playgroud)
这就是我处理显示板中自定义帖子类型的元框,保存数据等的方式。
function add_bez_oznaka_text_metabox() {
add_meta_box('poslovi_newsletter_meta', 'Tekst mejla za korisnike bez oznaka', 'bez_oznaka_textarea', 'poslovi-newsletter', 'normal', 'default');
}
add_action( 'add_meta_boxes', 'add_bez_oznaka_text_metabox' );
function bez_oznaka_textarea( $post ) {
wp_nonce_field( basename( __FILE__ ), 'poslovi_newsletter_nonce' );
$poslovi_newsletter_stored_meta = get_post_meta( $post->ID );
?>
<p>
<label for="meta-textarea" class="poslovi_newsletter-row-title"><?php _e( …Run Code Online (Sandbox Code Playgroud) meta-boxes ×10
wordpress ×8
php ×4
arrays ×1
editor ×1
field ×1
html-select ×1
metadata ×1
tinymce ×1
woocommerce ×1