Custom Fields
Re-Envisioned
Support Meta Box Geolocation google maps vs. include/exclude

  • Creator
    Topic
  • #5448
    web-crossing
    Participant

    Hi,
    if I add a dynamic google maps via a selectable box the API-Key gets lost (nasty description).

    So - if i have folling definition the map is not shown but the javascript error message that no API-Key is given.
    If i remove the 'hidden'-statement the map is shown as usual.

    best regards,
    niko

                array(
                    'id'   =>  "{$prefix}address",
                    'name' => __( 'Address', 'webx' ),
                    'type' => 'text',
                    'std'  => __( 'Innsbruck, Austria', 'webx' ),
                    'hidden' => array( "{$prefix}type", '!=', 4),
                ),
                array(
                    'id'            =>  "{$prefix}map",
                    'name'          => __( 'Location', 'webx' ),
                    'type'          => 'map',
                    'std'           => '47.2643292,11.3963643',
                    'address_field' => "{$prefix}address",
                    'api_key'       => 'super-fancy-google-maps-key',
                    'hidden' => array( "{$prefix}type", '!=', 4),
                ),
Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #5470
    Tan Nguyen
    Participant

    Dear Web Crossing,

    Can you please send me full code. I've tried added your two fields to the example and it works.


    add_filter( 'rwmb_meta_boxes', function( $meta_boxes )
    {
    $meta_boxes[] = array(
    'id' => 'geolocation',
    'title' => 'GeoLocation',
    'context' => 'normal',
    'priority' => 'high',
    // Tell WP this Meta Box is GeoLocation
    'geo' => true,
    // Or you can set advanced settings for Geo, like this example:
    // Restrict results to Australia only.
    // Uncomment to use it.
    // 'geo' => array(
    // 'componentRestrictions' => array(
    // 'country' => 'au'
    // )
    // ),
    'fields' => array(
    array(
    'id' => "address",
    'name' => __( 'Address', 'webx' ),
    'type' => 'text',
    'std' => __( 'Innsbruck, Austria', 'webx' ),
    'hidden' => array( "post_format", 'aside'),
    ),
    array(
    'id' => "map",
    'name' => __( 'Location', 'webx' ),
    'type' => 'map',
    'std' => '47.2643292,11.3963643',
    'address_field' => "address",
    'api_key' => 'super-fancy-google-maps-key',
    'hidden' => array( "post_format", 'aside'),
    ),
    // Auto populate `postal_code` to this field
    array(
    'type' => 'number',
    'name' => 'Postcode',
    'id' => 'postal_code'
    ),
    // Auto populate also works with Select field. In case you want to limit your result like this example.
    // Auto populate short name of `administrative_area_level_1`. For example: QLD
    array(
    'type' => 'select',
    'name' => 'State',
    'placeholder' => 'Select a State',
    'options' => array(
    'ACT' => 'ACT',
    'QLD' => 'QLD',
    'NSW' => 'NSW',
    'NT' => 'NT',
    'SA' => 'SA',
    'TAS' => 'TAS',
    'VIC' => 'VIC',
    'WA' => 'WA'
    ),
    'id' => 'administrative_area_level_1_short'
    ),
    // You can set different ID but still can auto populate `route` to this field.
    array(
    'type' => 'text',
    'name' => 'Route',
    'id' => 'dummy_field',
    'binding' => 'route'
    ),
    // We have custom `geometry` address component. Which is `lat + ',' + lng`
    array(
    'type' => 'text',
    'name' => 'Geometry',
    'id' => 'geometry'
    ),
    // But you can always use Binding Template to bind data like so
    array(
    'type' => 'text',
    'name' => 'Geometry with custom template',
    'id' => 'geometry2',
    'binding' => 'lat + "," + lng' // lat,lng
    ),
    // Here is the advanced usage of Binding Template.
    // Put any address component + anything you want
    array(
    'type' => 'text',
    'name' => 'State + Country',
    'id' => 'state_country',
    // Example Output: QLD AU
    'binding' => 'short:administrative_area_level_1 + " " + country'
    ),
    )
    );
    return $meta_boxes;
    } );

    view raw

    meta-box.php

    hosted with ❤ by GitHub

    Cheers!

    #5483
    web-crossing
    Participant

    Hi,
    here you go:

    <?php

    
    function content_element_metaboxes( $meta_boxes ) {
        $prefix = "webx-";
        $type_opt = array(0 => "Text", 1 => "Masonry Gallery", 2 => "Slider", 3 => "Big Picture", 4 => "Map", 5 => "Insta Feed", 6 => "Cite", 7 => "Interview");
    
        $just_text = array(
            'wpautop' => false,
            'media_buttons' => true,
            'textarea_rows' => 20,
            'teeny' => false,
            'dfw' => false,
            'tinymce' => true,
            'quicktags' => false
        );
    
        $meta_boxes[] = array(
            'title'      => __('The content', 'webx'),
            'context'    => 'normal',
            'priority'   => 'high',
            'post_types' => array( 'content_element'),
            'geo' => true,
            'fields' => array(
                array(
                    'name' => __('Type', 'webx'),
                    'id' => "{$prefix}type",
                    'type'  => "select",
                    'inline' => true,
                    'options' => $type_opt
                ),
                array(
                    'name' => __('Text', 'webx'),
                    'id' => "{$prefix}text",
                    'type'  => "wysiwyg",
                    'options' => $just_text,
                    'hidden' => array( "{$prefix}type", '!=', 0)
                ),
                array(
                    'id'               => "{$prefix}gallery",
                    'name'             => __('Images', 'webx'),
                    'type'             => 'image_advanced',
                    'force_delete'     => false,
                    'max_file_uploads' => 50,
                    'max_status'       => true,
                    'visible' => array( "{$prefix}type", 'in', [1, 2, 3])
                ),
                // Map requires at least one address field (with type = text)
                array(
                    'id'   =>  "{$prefix}address",
                    'name' => __( 'Address', 'webx' ),
                    'type' => 'text',
                    'std'  => __( 'Innsbruck, Austria', 'webx' ),
                    'visible' => array( "{$prefix}type", 4),
                ),
                array(
                    'id'            =>  "{$prefix}map",
                    'name'          => __( 'Location', 'webx' ),
                    'type'          => 'map',
                    'std'           => '47.2643292,11.3963643',
                    'address_field' => "{$prefix}address",
                    'api_key'       => 'AIzaSyBQDh2E_g4_UTvYb5_2y6WClAOCn3VqRLc',
                    'visible' => array( "{$prefix}type", 4),
                ),
                array(
                    'name' => __('Markers', 'webx'),
                    'id' => "{$prefix}markers",
                    'type' => 'group',
                    'clone'  => true,
                    'visible' => array( "{$prefix}type", 4),
                    'fields' => array(
                        array(
                            'name' => __('Address', 'webx'),
                            'type' => 'text',
                            'id'    => 'address_marker'
                        ),
                        array(
                            'name' => __('Text', 'webx'),
                            'type' => 'wysiwyg',
                            'id'    => 'markercontent',
                            'options' => $just_text
                        ),
                    ),
                ),
                array(
                    'id'   =>  "{$prefix}instagram",
                    'name' => __( 'Instagram ID', 'webx' ),
                    'dec' => __('get it here: ') . ".https://smashballoon.com/instagram-feed/find-instagram-user-id/",
                    'type' => 'text',
                    'size' => 100,
                    'hidden' => array( "{$prefix}type", '!=', 5),
                ),
                array(
                    'id'   =>  "{$prefix}cite",
                    'name' => __( 'cite', 'webx' ),
                    'type' => 'textarea',
                    'size' => 100,
                    'hidden' => array( "{$prefix}type", '!=', 6),
                ),
                array(
                    'id' => "{$prefix}interview-header",
                    'name' => __("Title", 'webx'),
                    'type' => 'text',
                    'size' => 120,
                    'hidden' => array( "{$prefix}type", '!=', 7),
                ),
                array(
                    'id' => "{$prefix}interview",
                    'name' => __("Interview", 'webx'),
                    'type' => 'group',
                    'hidden' => array( "{$prefix}type", '!=', 7),
                    'sort_clone' => true,
                    'clone'  => true,
                    'fields' => array(
                        array(
                            'name' => __('Question', 'webx'),
                            'type' => 'text',
                            'size' => 80,
                            'id'    => 'question'
                        ),
                        array(
                            'name' => __('Text', 'webx'),
                            'type' => 'wysiwyg',
                            'id'    => 'answer',
                            'options' => $just_text
                        ),
                    )
    
                )
    
            )
        );
        return $meta_boxes;
    }
    add_filter( 'rwmb_meta_boxes', 'content_element_metaboxes' );
    #5489
    Tan Nguyen
    Participant

    Hi,

    It works on my PC, did you:

    - Use the latest plugins version?
    - See any error in the console?

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘google maps vs. include/exclude’ is closed to new replies.