Last active
January 28, 2020 17:25
-
-
Save carmoreira/aaa14dc3479ad1b3e1488ab66ed04fa9 to your computer and use it in GitHub Desktop.
Interactive World Maps plugin - read from Custom Post Type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * With this approach, you would need to add "my_custom_map_data" to the map's advanced tab for the Interactive Regions | |
| * the map would then read from the custom post type and the fields specified below | |
| */ | |
| add_filter('iwm_input','my_custom_map_input'); | |
| function my_custom_map_input($input){ | |
| /* Conditional tag to populate the map automatically, if using CUSTOM POST TYPE as source */ | |
| if($input=='my_custom_map_data') { | |
| //EDIT HERE | |
| $cpt_id = 'YOUR_POST_TYPE_ID'; | |
| $region_code_meta = 'wpcf-regioncode'; //custom meta field name to fetch region code; | |
| /* | |
| OR If you're using coordinates, you'll need 2 fields | |
| $region_code_meta = array('wpcf-lat','wpcf-lon'); | |
| */ | |
| $tooltip_meta = 'wpcf-tooltip'; //custom meta field name to fetch tooltip info; | |
| $color_meta = 'wpcf-color'; //cutom meta field name to fetch color codes | |
| //AVOID EDIT BELOW | |
| $input = ''; | |
| $args = array( | |
| 'post_type' => $cpt_id, | |
| ); | |
| $cpt = new WP_Query( $args ); | |
| // The Loop | |
| if ( $cpt->have_posts() ) { | |
| while ( $cpt->have_posts() ) : $cpt->the_post(); | |
| if(is_array($region_code_meta)){ | |
| $regioncode = get_post_meta( get_the_ID(), $region_code_meta[0], true ).' '.get_post_meta( get_the_ID(), $region_code_meta[1], true ); | |
| } else { | |
| $regioncode = get_post_meta( get_the_ID(), $region_code_meta, true ); | |
| } | |
| $tooltiptitle = get_the_title(); | |
| $tooltipinfo = get_post_meta( get_the_ID(), $tooltip_meta, true );; | |
| $actionvalue = do_shortcode(get_the_content()); | |
| $colorcode = get_post_meta( get_the_ID(), $color_meta, true ); | |
| //to clean the content from commas (,) and semi-colons (;) | |
| $oreplace = array(",", ";"); | |
| $ofinal = array(",", ";"); | |
| $actionvalue = str_replace($oreplace, $ofinal, $actionvalue); | |
| //model: Region Code, Tooltip Title, Tooltip info, Action Value (URL), Color Code; | |
| $input .= $regioncode.','.$tooltiptitle.','.$tooltipinfo.','.$actionvalue.','.$colorcode.';'; | |
| endwhile; | |
| } | |
| /* Restore original Post Data */ | |
| wp_reset_postdata(); | |
| } | |
| return $input; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment