Support » Plugin: Jetpack by WordPress.com » Set value in custom field using post by email

  • Hi
    I’m making a travel blog, and I need to be able to post by email. I also need to setup a custom field for the post to store location information, to be able to show all geotagged posts on a map.

    The custom field should look like this, and I need to specify the value field when posting by email.

    Name = “OSM_geo_data”
    Value = “LAT, LON”

    I have found a way to automatically create the custom field by supplying this code in the functions.php

    add_action('publish_page', 'add_custom_field_automatically');
    add_action('publish_post'. 'add_custom_field_automatically');
    function add_custom_field_automatically($post_ID) {
        global $wpdb;
        if(!wp_is_post_revision($post_ID)) {
            add_post_meta($post_ID, 'OSM_geo_data', 'CUSTOM VALUE', true);
        }
    }

    But then I need to somehow pass a value to use istead of COSTOM VALUE in the above..

    Any suggestions ?

    https://wordpress.org/plugins/jetpack/

Viewing 3 replies - 1 through 3 (of 3 total)
  • A little bump. Maybe someone new could have a look 🙂
    Thanks in advance.

    Plugin Contributor Richard Archambault

    (@richardmtl)

    Happiness Engineer

    Hi, great try, but custom fields aren’t supported in Post By Email. You’d have to try including your own custom shortcode with the custom values, maybe, and then get that parsed before your add_custom_field_automatically runs?

    elevensuns

    (@elevensuns)

    Check this plugin.  Its called CF Setter and it lets you define custom fields from the body of an email.

    http://hypertext.net/projects/cfsetter/

    Followed the instructions on this page.

    Include the following short code on the body of the email:

    [cf]value_to_insert_in custom_field[/cf]

    It inserts the value in the custom field in worpress when posting by email.

    To display the field I used the following short code on the template file:

    <!-- Display Custom Field -->
    <?php
    	$myname = get_post_meta($post->ID, ‘custom_field_name, true);
    	if ( $myname ) {
    ?>
    
    <h3 ><?php the_meta(custom_field_name) ?></h3>
    
    <?php }
    else {
     }
    ?>
    <!-- End Display Custom Field -->

    It evaluates if the field is empty and then shows results.

    Substitute custom_field_name for the name of your Custom Field Name

    It works like a charm! Hope it works for you guys!

    http://codex.wordpress.org/Custom_Fields
    http://codex.wordpress.org/Function_Reference/get_post_meta

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Set value in custom field using post by email’ is closed to new replies.