WordPress.org

Ready to get started?Download WordPress

Forums

Jetpack by WordPress.com
Set value in custom field using post by email (4 posts)

  1. krintel
    Member
    Posted 3 months ago #

    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/

  2. krintel
    Member
    Posted 3 months ago #

    A little bump. Maybe someone new could have a look :)
    Thanks in advance.

  3. Richard Archambault
    Happiness Engineer
    Plugin Author

    Posted 2 months ago #

    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?

  4. elevensuns
    Member
    Posted 3 weeks ago #

    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

Reply

You must log in to post.

About this Plugin

About this Topic