Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WPATX Metadata
// display the top local, top unique and key varietals metaboxes in the admin area
public static function local_meta_box_display( $post, $metabox ) {
$prefix = $metabox['args']['name'];
$child_regions = hmc_get_child_regions();
$current_regions = array();
if ( get_the_terms( $post->ID, 'local_highlights' ) ) {
$current_regions = wp_list_pluck( get_the_terms( $post->ID, 'local_highlights' ), 'name' );
}
echo '<input type="hidden" name="prefix[]" value ="'. esc_attr( $prefix ) .'"/>';
// Add an nonce field so we can check for it later.
wp_nonce_field( 'local_highlights_box', 'local_highlights_box_nonce' );
foreach ( $child_regions as $key => $value ) {
// Remove any '-fr' or other language codes added to values is removed
$clean_key = HMC_Regionalization::strip_lang_code( $key ); ?>
<input type="checkbox" name="<?php echo esc_attr( $prefix . 'local_highlights[]' ); ?>" value="<?php echo esc_attr( $prefix . $key ); ?>" <?php checked( true, in_array( $prefix . $clean_key, $current_regions ) ); ?>/>
<label for="local-highlight-<?php echo esc_attr( $key ); ?> ">
<?php echo esc_html( $value ); ?>
</label>
</br>
<?php }
}
// Save the term to the taxonomy when the post is saved.
public static function save_local_highlights_meta_box( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['local_highlights_box_nonce'] ) )
return $post_id;
$nonce = $_POST['local_highlights_box_nonce'];
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $nonce, 'local_highlights_box' ) )
return $post_id;
// If this is an autosave, our form has not been submitted,
// so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check the user's permissions.
if ( 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
// Sanitize the user input.
$prefixes = $_POST['prefix'];
$local_highlights = array();
foreach($prefixes as $prefix) {
if ( isset( $_POST[$prefix .'local_highlights'] ) ) {
$local_highlights = array_merge( $local_highlights, $_POST[$prefix .'local_highlights'] );
}
}
// Update the product highlight terms.
wp_set_object_terms($post_id, $local_highlights, 'local_highlights');
}
// Save the term to the taxonomy when the post is saved.
public static function save_local_highlights_meta_box( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['local_highlights_box_nonce'] ) )
return $post_id;
$nonce = $_POST['local_highlights_box_nonce'];
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $nonce, 'local_highlights_box' ) )
return $post_id;
// If this is an autosave, our form has not been submitted,
// so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check the user's permissions.
if ( 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( ! current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
// Sanitize the user input.
$prefixes = $_POST['prefix'];
$local_highlights = array();
foreach($prefixes as $prefix) {
if ( isset( $_POST[$prefix .'local_highlights'] ) ) {
$local_highlights = array_merge( $local_highlights, $_POST[$prefix .'local_highlights'] );
}
}
// Update the product highlight terms.
wp_set_object_terms($post_id, $local_highlights, 'local_highlights');
}
<?php
namespace AMCN\Core\Post_Meta\Images;
/**
* Load various actions for this post meta
*
* @since 0.1.0
*
* @return void.
*/
function load() {
add_action( 'add_meta_boxes', __NAMESPACE__ . '\show_images_store' );
add_action( 'save_post', __NAMESPACE__ . '\show_images_update' );
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\admin_scripts' );
}
/**
* Create Meta box for the show images meta
*
* @since 0.1.0
*
* @return void.
*/
function show_images_store() {
add_meta_box(
'show-images',
__( 'Show Images', 'amcn' ),
__NAMESPACE__ . '\show_images_display',
'amcn_show',
'advanced'
);
}
/**
* Callback func for show images meta box.
*
* @since 0.1.0
*
* @param object $post post object
*
*/
function show_images_display( $post ) {
// Add an nonce field so we can check for it later.
wp_nonce_field( 'show_media_metabox', 'show_media_metabox_nonce' );
$show_stored_meta = get_post_meta( $post->ID ); ?>
<p>
<h4><label for="show-masthead"><?php _e( 'Show Masthead' , 'amcn' );?></label></h4>
<input type="text" name="show_masthead" id="show-masthead" value="<?php if ( isset ( $show_stored_meta['show_masthead'] ) ){ echo $show_stored_meta['show_masthead'][0]; } ?>" />
<input type="button" id="show-masthead-button" class="button" value="Choose or Upload an Image" />
</p>
<?php if ( isset ( $show_stored_meta['show_masthead'] ) ){
echo '<div class="image-preview">';
echo '<p><img src="' . $show_stored_meta['show_masthead'][0] . '" width="150"/></p>';
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>';
echo '</div>';
} ?>
<p>
<h4><label for="show-logo"><?php _e( 'Show Logo' , 'amcn' );?></label></h4>
<input type="text" name="show_logo" id="show-logo" value="<?php if ( isset ( $show_stored_meta['show_logo'] ) ){ echo $show_stored_meta['show_logo'][0]; } ?>" />
<input type="button" id="show-logo-button" class="button" value="Choose or Upload an Image" />
</p>
<?php if ( isset ( $show_stored_meta['show_logo'] ) ){
echo '<div class="image-preview">';
echo '<p><img src="' . $show_stored_meta['show_logo'][0] . '" width="150"/></p>';
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>';
echo '</div>';
} ?>
<p>
<h4><label for="show-poster"><?php _e( 'Show Poster' , 'amcn' );?></label></h4>
<input type="text" name="show_poster" id="show-poster" value="<?php if ( isset ( $show_stored_meta['show_poster'] ) ){ echo $show_stored_meta['show_poster'][0]; } ?>" />
<input type="button" id="show-poster-button" class="button" value="Choose or Upload an Image" />
</p>
<?php if ( isset ( $show_stored_meta['show_poster'] ) ){
echo '<div class="image-preview">';
echo '<p><img src="' . $show_stored_meta['show_poster'][0] . '" width="150"/></p>';
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>';
echo '</div>';
} ?>
<p>
<h4><label for="small-tout"><?php _e( 'Small Tout Image' , 'amcn' );?></label></h4>
<input type="text" name="small_tout" id="small-tout" value="<?php if ( isset ( $show_stored_meta['small_tout'] ) ){ echo $show_stored_meta['small_tout'][0]; } ?>" />
<input type="button" id="small-tout-button" class="button" value="Choose or Upload an Image" />
</p>
<?php if ( isset ( $show_stored_meta['small_tout'] ) ){
echo '<div class="image-preview">';
echo '<p><img src="' . $show_stored_meta['small_tout'][0] . '" width="150"/></p>';
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>';
echo '</div>';
} ?>
<p>
<h4><label for="large-tout"><?php _e( 'Large Tout Image' , 'amcn' );?></label></h4>
<input type="text" name="large_tout" id="large-tout" value="<?php if ( isset ( $show_stored_meta['large_tout'] ) ){ echo $show_stored_meta['large_tout'][0]; } ?>" />
<input type="button" id="large-tout-button" class="button" value="Choose or Upload an Image" />
</p>
<?php if ( isset ( $show_stored_meta['large_tout'] ) ){
echo '<div class="image-preview">';
echo '<p><img src="' . $show_stored_meta['large_tout'][0] . '" width="150"/></p>';
echo '<button class="remove-image">'. __( 'Remove Image' , 'amctv' ) .'</button>';
echo '</div>';
} ?>
<?php
}
/**
* Save the meta when the post is saved.
*
* @since 0.1.0
*
* @param int $post_id The ID of the post being saved.
*/
function show_images_update( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['show_media_metabox_nonce'] ) )
return $post_id;
$nonce = $_POST['show_media_metabox_nonce'];
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $nonce, 'show_media_metabox' ) )
return $post_id;
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Check the user's permissions.
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
// Checks for input and sanitizes/saves if needed
if( isset( $_POST[ 'show_logo' ] ) ) {
update_post_meta( $post_id, 'show_logo', $_POST[ 'show_logo' ] );
}
if( isset( $_POST[ 'small_show_poster' ] ) ) {
update_post_meta( $post_id, 'small_show_poster', $_POST[ 'small_show_poster' ] );
}
if( isset( $_POST[ 'large_show_poster' ] ) ) {
update_post_meta( $post_id, 'large_show_poster', $_POST[ 'large_show_poster' ] );
}
if( isset( $_POST[ 'small_tout' ] ) ) {
update_post_meta( $post_id, 'small_tout', $_POST[ 'small_tout' ] );
}
if( isset( $_POST[ 'large_tout' ] ) ) {
update_post_meta( $post_id, 'large_tout', $_POST[ 'large_tout' ] );
}
}
/**
* Gets and array of post types that pertain to social repeater meta
*
* @since 0.1.0
*
* @return array An array of post type slugs.
*/
function get_post_types() {
return apply_filters( 'amcn_show_images', array() );
}
/**
* admin_scripts function
*
* @since 0.1.0
* @return void
*/
function admin_scripts() {
global $typenow;
if( 'amcn_show' === $typenow ) {
wp_enqueue_script( 'show-image-upload', AMCN_ASSETS . '/js/src/show-image-upload.js', array( 'jquery' ) );
}
}
//getting show poster
<?php $show_poster = get_post_meta( $menu_item->object_id, 'show_poster', true ); ?>
// getting show tout
<?php echo esc_url( get_post_meta( absint( $footer_posts['left'] ) , 'large_tout' , true ) ) ;?>
// registering field groups in ACF
register_field_group(array (
'id' => 'acf_menu-options',
'title' => 'Menu Options',
'fields' => array (
array (
'key' => 'field_51cd3de523b05',
'label' => 'Havest Table Items',
'name' => 'harvest_table',
'type' => 'repeater',
'sub_fields' => array (
array (
'default_value' => '',
'formatting' => 'none',
'key' => 'field_51cd3de523b06',
'label' => 'item title',
'name' => 'item_title',
'type' => 'text',
'column_width' => '',
),
array (
'default_value' => '',
'formatting' => 'br',
'key' => 'field_51cd3de523b07',
'label' => 'item description',
'name' => 'item_description',
'type' => 'textarea',
'column_width' => '',
),
),
'row_min' => 0,
'row_limit' => '',
'layout' => 'table',
'button_label' => 'Add Menu Item',
),
array (
'key' => 'field_51cd3e2cacbf1',
'label' => 'Chef Selection Items',
'name' => 'chef_selections',
'type' => 'repeater',
'sub_fields' => array (
array (
'default_value' => '',
'formatting' => 'none',
'key' => 'field_51cd3e2cacbf2',
'label' => 'item title',
'name' => 'item_title',
'type' => 'text',
'column_width' => '',
),
array (
'default_value' => '',
'formatting' => 'br',
'key' => 'field_51cd3e2cacbf3',
'label' => 'item description',
'name' => 'item_description',
'type' => 'textarea',
'column_width' => '',
),
),
'row_min' => 0,
'row_limit' => '',
'layout' => 'table',
'button_label' => 'Add Menu Item',
),
array (
'key' => 'field_51cd3e669ca6a',
'label' => 'Ala Carte Items',
'name' => 'ala_carte',
'type' => 'repeater',
'sub_fields' => array (
array (
'default_value' => '',
'formatting' => 'none',
'key' => 'field_51cd3e669ca6b',
'label' => 'item title',
'name' => 'item_title',
'type' => 'text',
'column_width' => '',
),
array (
'default_value' => '',
'min' => '',
'max' => '',
'step' => 53,
'key' => 'field_51cd3e87cf184',
'label' => 'item_price',
'name' => 'item_price',
'type' => 'number',
'column_width' => '',
),
array (
'default_value' => '',
'formatting' => 'br',
'key' => 'field_51cd3e669ca6c',
'label' => 'item description',
'name' => 'item_description',
'type' => 'textarea',
'column_width' => '',
),
),
'row_min' => 0,
'row_limit' => '',
'layout' => 'table',
'button_label' => 'Add Menu Item',
),
array (
'key' => 'field_51cd3ecceab74',
'label' => 'On The Side Items',
'name' => 'on_the_side',
'type' => 'repeater',
'sub_fields' => array (
array (
'default_value' => '',
'formatting' => 'none',
'key' => 'field_51cd3ecceab75',
'label' => 'item title',
'name' => 'item_title',
'type' => 'text',
'column_width' => '',
),
array (
'default_value' => '',
'min' => '',
'max' => '',
'step' => 53,
'key' => 'field_51cd3ecceab76',
'label' => 'item_price',
'name' => 'item_price',
'type' => 'number',
'column_width' => '',
),
array (
'default_value' => '',
'formatting' => 'br',
'key' => 'field_51cd3ecceab77',
'label' => 'item description',
'name' => 'item_description',
'type' => 'textarea',
'column_width' => '',
),
),
'row_min' => 0,
'row_limit' => '',
'layout' => 'table',
'button_label' => 'Add Menu Item',
),
// menu template for ACF data above
<?php
/*
Template Name: Menu
*/
?>
<?php get_header();?>
<section id="sitewrap" role="document">
<section id="content" role="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php get_template_part('content', get_post_format()); ?>
</article>
<?php endwhile; endif; ?>
<section id="menu-wrap">
<ul id="menu-sections">
<div class="divider"></div>
<li id="harvest-table">
<section class="sub-heading">
<h2><?php _e('Harvest Tables');?></h2>
<p><?php _e('Explore and indulge, any or all');?></p>
</section>
<section class="menu-section">
<?php if(get_field('harvest_table')): while(has_sub_field('harvest_table')):?>
<h3><?php the_sub_field('item_title') ;?></h3>
<p><?php the_sub_field('item_description');?></p>
<?php endwhile; endif; ?>
</section>
<li id="chef-selections" >
<section class="sub-heading">
<h2><?php _e('Chef Selections');?></h2>
<p><?php _e('Unlimited samplings, offered tableside');?></p>
</section>
<section class="menu-section">
<?php if(get_field('chef_selections')): while(has_sub_field('chef_selections')):?>
<h3><?php the_sub_field('item_title') ;?></h3>
<p><?php the_sub_field('item_description');?></p>
<?php endwhile; endif; ?>
</section>
</li>
<div class="divider"></div>
<li id="ala-carte">
<section class="sub-heading">
<h2><?php _e('Ala Carte');?></h2>
</section>
<section class="menu-section">
<?php if(get_field('ala_carte')): while(has_sub_field('ala_carte')):?>
<h3><?php the_sub_field('item_title') ;?><span><?php the_sub_field('item_price') ;?></span></h3>
<p><?php the_sub_field('item_description');?></p>
<?php endwhile; endif; ?>
</section>
</li>
<li id="extras">
<section class="sub-heading"><h2><?php _e('On the Side');?></h2></section>
<?php if(get_field('on_the_side')): while(has_sub_field('on_the_side')):?>
<h3><?php the_sub_field('item_title') ;?><span><?php the_sub_field('item_price') ;?></span></h3>
<?php endwhile; endif; ?>
<section class="sub-heading"><h2><?php _e('Sliders');?></h2></section>
<?php if(get_field('sliders')): while(has_sub_field('sliders')):?>
<h3><?php the_sub_field('item_title') ;?><span><?php the_sub_field('item_price') ;?></span></h3>
<?php endwhile; endif; ?>
<section id="liquid-market">
<section class="sub-heading"><h2><?php _e('Liquid Market');?></h2></section>
<h3><?php the_field('liquid_market');?></h3>
</section>
</li>
</ul>
</section>
</section><!-- content -->
</section>
<?php get_footer();?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.