Untitled

 avatar
unknown
plain_text
a year ago
8.5 kB
5
Indexable
add_action( 'acf/init', function() {
    acf_add_options_page( array(
        'page_title' => 'Distillery featured whisky',
        'menu_slug' => 'distillery-featured-whisky',
        'parent_slug' => 'edit.php?post_type=distillery',
        'position' => '',
        'redirect' => false,
    ) );
} );


    acf_add_local_field_group( array(
        'key' => 'group_65a5039e6ae32',
        'title' => 'Distillery region',
        'fields' => array(
            array(
                'key' => 'field_65a5039e1ba2c',
                'label' => 'Region image',
                'name' => 'region_image',
                'aria-label' => '',
                'type' => 'image',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => array(
                    'width' => '',
                    'class' => '',
                    'id' => '',
                ),
                'return_format' => 'url',
                'library' => 'all',
                'min_width' => '',
                'min_height' => '',
                'min_size' => '',
                'max_width' => '',
                'max_height' => '',
                'max_size' => '',
                'mime_types' => '',
                'preview_size' => 'medium',
            ),
            array(
                'key' => 'field_65a503b21ba2d',
                'label' => 'Full description',
                'name' => 'full_description',
                'aria-label' => '',
                'type' => 'wysiwyg',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => array(
                    'width' => '',
                    'class' => '',
                    'id' => '',
                ),
                'default_value' => '',
                'tabs' => 'all',
                'toolbar' => 'full',
                'media_upload' => 1,
                'delay' => 0,
            ),
            array(
                'key' => 'field_65a51c502d49c',
                'label' => 'Featured whisky',
                'name' => 'featured_whisky',
                'aria-label' => '',
                'type' => 'post_object',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => array(
                    'width' => '',
                    'class' => '',
                    'id' => '',
                ),
                'post_type' => array(
                    0 => 'product',
                ),
                'post_status' => '',
                'taxonomy' => '',
                'return_format' => 'object',
                'multiple' => 1,
                'allow_null' => 0,
                'bidirectional' => 0,
                'ui' => 1,
                'bidirectional_target' => array(
                ),
            ),
        ),
        'location' => array(
            array(
                array(
                    'param' => 'taxonomy',
                    'operator' => '==',
                    'value' => 'distillery-region',
                ),
            ),
        ),
        'menu_order' => 0,
        'position' => 'normal',
        'style' => 'default',
        'label_placement' => 'top',
        'instruction_placement' => 'label',
        'hide_on_screen' => '',
        'active' => true,
        'description' => '',
        'show_in_rest' => 0,
    ) );

    acf_add_local_field_group( array(
        'key' => 'group_65a5271a1d6ea',
        'title' => 'Featured whisky',
        'fields' => array(
            array(
                'key' => 'field_65a5271a39deb',
                'label' => 'Featured whisky',
                'name' => 'featured_whisky',
                'aria-label' => '',
                'type' => 'post_object',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => array(
                    'width' => '',
                    'class' => '',
                    'id' => '',
                ),
                'post_type' => array(
                    0 => 'product',
                ),
                'post_status' => '',
                'taxonomy' => '',
                'return_format' => 'object',
                'multiple' => 1,
                'allow_null' => 0,
                'bidirectional' => 0,
                'ui' => 1,
                'bidirectional_target' => array(
                ),
            ),
        ),
        'location' => array(
            array(
                array(
                    'param' => 'options_page',
                    'operator' => '==',
                    'value' => 'distillery-featured-whisky',
                ),
            ),
        ),
        'menu_order' => 0,
        'position' => 'normal',
        'style' => 'default',
        'label_placement' => 'top',
        'instruction_placement' => 'label',
        'hide_on_screen' => '',
        'active' => true,
        'description' => '',
        'show_in_rest' => 0,
    ) );











<?php

$terms = get_terms( 'distillery-region' );

if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    foreach ( $terms as $term ) { ?>
        <div>
            <img src="<?php echo get_field('region_image', $term); ?>" alt="">
            <?php

            echo $term->name;
            echo '<br>';
            echo $term->description;?>
        </div>
    <?php
    }
}



<?php
$terms = get_terms( 'distillery-region' );

if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    foreach ( $terms as $term ) { ?>
        <div>
            <img src="<?php echo get_field('region_image', $term); ?>" alt="">
            <?php

            echo $term->name;
            echo '<br>';
            echo get_field('full_description', $term);

            wp_reset_query();
            $args = array(
                'post_type' => 'distillery',
                'tax_query' => array(
                    array(
                        'taxonomy' => $term->taxonomy,
                        'field' => 'slug',
                        'terms' => $term->slug,
                    ),
                ),
            );

            $loop = new WP_Query($args);
            if($loop->have_posts()) ?>
                    <ul>
            <?php {

                while($loop->have_posts()) : $loop->the_post(); ?>
                    <li><a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a></li>
               <?php endwhile; ?>
            </ul>
            <?php }
            ?>
        </div>
    <?php
    }
}





<?php
get_header(); ?>

    SIngle distillery


<?php
$distillery_featured_whisky = get_field('featured_whisky');

if ($distillery_featured_whisky) {
    $featured_whisky = $distillery_featured_whisky;

} else {
    $term_list = get_the_terms(get_the_ID(), 'distillery-region');

    $region_featured_whisky = get_field('featured_whisky', $term_list[0]);
    if ($region_featured_whisky) {
        $featured_whisky = $region_featured_whisky;
    }else{
        $featured_whisky = get_field('featured_whisky', 'option');
    }

}

if ($featured_whisky){
    echo " Featured whisky";
    var_dump($featured_whisky);
}

?>


<?php
get_footer();







    $distillery_regions_labels = array(
        'name'              => _x( 'Region', 'taxonomy general name' ),
        'singular_name'     => _x( 'Region', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Region' ),
        'all_items'         => __( 'All Regions' ),
        'parent_item'       => __( 'Parent Region' ),
        'parent_item_colon' => __( 'Parent Region:' ),
        'edit_item'         => __( 'Edit Region' ),
        'update_item'       => __( 'Update Region' ),
        'add_new_item'      => __( 'Add New Region' ),
        'new_item_name'     => __( 'New Region' ),
        'menu_name'         => __( 'Region' ),
    );
    $distillery_regions_args   = array(
        'hierarchical'      => true, // make it hierarchical (like categories)
        'labels'            => $distillery_regions_labels,
        'show_ui'           => true,
        'show_admin_column' => false,
        'query_var'         => true,
        'show_in_rest' => true,
        'rewrite'           => [ 'slug' => 'distillery-region' ],
    );
    register_taxonomy( 'distillery-region', [ 'distillery' ], $distillery_regions_args );
Editor is loading...
Leave a Comment