WordPress.org

Ready to get started?Download WordPress

Forums

Comprehensive Google Map Plugin
[resolved] Custom Field as destination (2 posts)

  1. Miki80
    Member
    Posted 4 months ago #

    Hello, thanks for the great plugin!!!

    Can you/someone please help me with the following,with my limited knowledge of php but with great effort i have not been able to get this working, please see the code below.

    Function to get the custom field:

    // Get Custom Field Template Values
    function getCustomField($theField) {
       global $post;
       $block = get_post_meta($post->ID, $theField);
       if($block){
    	foreach(($block) as $blocks) {
    	echo $blocks;
    	}
       }
    }

    Then I try to create a proper string to use as shortcode

    $content = "[google-map-v3 width=\"350\"
    	height=\"350\"
    	zoom=\"4\"
    	addmarkerlist=\"".getCustomField('cf_Destination')"{}1-default.png\"
    	maptype=\"roadmap\"
    	mapalign=\"center\"
    	directionhint=\"false\"
            ...
    	showpanoramio=\"false\"]";

    The problem is that whatever I try the custom field gets inserted in front of the shortcode and not at the location where it is in the string.

    Swiss[google-map-v3 width="350" height="350" zoom="4" addmarkerlist=""{}1-default.png\" ... etc

    Have tried multiple themes, getting the same result, what am I doing wrong ???
    Any help or other solution is much appreciated

    Thanks

    https://wordpress.org/plugins/comprehensive-google-map-plugin/

  2. Miki80
    Member
    Posted 4 months ago #

    using WP query instead of the function above did the trick.

    global $wp_query;
    $postid = $wp_query->post->ID;
    $dest = get_post_meta($postid, 'cf_destination', true);

    then I can use $dest in the addmarkerlist shortcode.

Reply

You must log in to post.

About this Plugin

About this Topic