我想将metabox添加到自定义帖子列表中,并在编辑或添加帖子屏幕上选择任意两个。最后,当文章发布时,将其显示在单个文章页面上。请帮帮我!任何帮助都将不胜感激。。。。
add_action( \'add_meta_boxes\', function () {
add_meta_box(
\'yourcustom_sectionid\',
__( \' Custom Offer Section\', \'yourtextdomain\' ),
function ( $post ) {
wp_nonce_field( plugin_basename( __FILE__ ), \'yourcustom_noncename\' );
$cstm = get_post_meta(get_the_ID(),\'yourcustom_meta\',true);
echo "<pre>".print_r($cstm,true)."</pre>";
$getPostsToSelect = get_posts(\'post_type=offers&numberposts=-1\');
foreach ($getPostsToSelect as $aPostsToSelect) {
?>
<label>
<input
type=\'checkbox\'
name=\'yourcustom_meta[]\'
class=\'postsToSelect\'
value=\'<?php echo $aPostsToSelect->ID ?>\'
/>
<?php echo $aPostsToSelect->post_title ?>
</label><br />
<?php
}
},
\'listing\'
);
} );
and then below:
echo "<script type=\'text/javascript\'>
var limit = 2;
jQuery(\'input.single-checkbox\').on(\'change\', function(evt) {
if(jQuery(\'input.single-checkbox:checked\').length > limit) {
this.checked = false;
}
});
</script>";
但是jquery似乎无法选择这两个复选框