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

  1. krintel
    Posted 2 years ago #

    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 ?


  2. krintel
    Posted 2 years ago #

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

  3. Richard Archambault
    Happiness Engineer
    Plugin Contributor

    Posted 2 years 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
    Posted 2 years ago #

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


    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 -->
    	$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!


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Jetpack by WordPress.com
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic