• Resolved carlae

    (@carlae)


    Is it possible to activate the checkbox “google maps weergeven” permanently bij default?
    In my case I would like to permanently check this box in a Custom Post, for all the new custom posts instead of checking this box each time for each post.
    Can I use the function pronamic_google_maps_is_active() for this? And if so, how should I use this. Which arguments, parameters is should use, and should this go in de function.php or in the template single-(post-type) of archive-(post-type)? I already added this in my template:

    <?php
    if ( function_exists( 'pronamic_google_maps' ) ) {
        pronamic_google_maps( array(
            'width'  => 290,
            'height' => 200
        ) );
    }
    ?>

    but than I still also have to check the checkbox.

    http://wordpress.org/plugins/pronamic-google-maps/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello carlae.

    The pronamic_google_maps() method also checks if that tickbox has been selected.

    It is a good idea to be able to specify its default state per post type, we will look to adding this.

    For now, if you want a solution, you can always add a hook into the save_post action ( http://codex.wordpress.org/Plugin_API/Action_Reference/save_post ) that checks for post_type, and then

    update_post_meta( $post_id, '_pronamic_google_maps_active', 'true' );

    This would tell Pronamic Google Maps that it is active every time you update ( or on the first Publish ).

    That would also mean you can’t turn it off and if thats ok, then the solution above works.

    If you do want to be able to turn it off selectively for some, you could always write some javascript that is inserted into the admin edit screen.

    $('#pgm-active-field').attr('checked', 'checked');

    should do it.

    Hope that gives you some good information to get started, until we develop our own interface. It could be a while, so if important, don’t wait for the update.

    Thread Starter carlae

    (@carlae)

    It sounds like a good solution but it’s not working. I’m not a real hero with code, I must be doing something wrong. I put the following code in my function.php:

    <?php function save_theatre_meta( $post_id ) {
        $slug = 'theatre';
        if ( $slug != $_POST['theatre'] ) {
            return;
        }
        update_post_meta( $post_id, '_pronamic_google_maps_active', 'true' );
    
    }
    add_action( 'save_post', 'save_theatre_meta');
    ?>

    I hope you can tell me what I’m doing wrong.

    Almost. The reference to $_POST must be the field ‘post_type’

    <?php
    
    function save_theatre_meta( $post_id ) {
    	if ( 'theatre' !== filter_input( INPUT_POST, 'post_type', FILTER_SANITIZE_STRING ) )
    		return;
    
    	update_post_meta( $post_id, '_pronamic_google_maps_active', true );
    }
    add_action( 'save_post', 'save_theatre_meta' );

    Give that a try

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘activate check-box "google maps weergeven" permanently (by default)’ is closed to new replies.