• Resolved almemedia

    (@almemedia)


    First of – what a great plugin! But I have one question – how do I put part of the content of an email into a custom field?
    Example: I want be able to send a mail like:
    Prio: 1
    Description: This is a description

    And than let postie set the custom field prio to 1 and the content to “This is a description”. I know I should be able to do it with filterPostie.php but don’t know really how.

    I have figured out a part:

    function add_custom_field($post) {
        add_post_meta($post['ID'], 'prio', $prio);
    
        return $post;
    }
    add_filter('postie_post_before', 'add_custom_field');

    But how do I parse the content to get out the 1 and the text after description?

    Thanks!

    https://www.ads-software.com/plugins/postie/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Wayne Allen

    (@wayneallen-1)

    Glad you like the plugin.

    You need to do some PHP string manipulation on $post[‘post_content’]

    This is tricky if your email is in html format. In fact Postie itself has trouble with this in some places.

    You may be better off using something like:

    {{Prio: 1}}
    {{Description: This is a description}}

    As it is much easier to find ‘{{‘ and ‘}}’ than the end of the line.

    Take a look at the strpos() and substr() functions.

    https://www.php.net/strpos
    https://www.php.net/substr

    Thread Starter almemedia

    (@almemedia)

    Have tried this now several days, but I can’t get it to work at all. I don’t even get the content to a custom field. How do start?
    Is the content of the message stored in: $post[‘post_content’] or how do I start parsing the data.

    Thanks in advance!

    Plugin Author Wayne Allen

    (@wayneallen-1)

    The $post array is the same as the one described here:
    https://codex.www.ads-software.com/Function_Reference/wp_insert_post

    Are you using add_post_meta()?
    https://codex.www.ads-software.com/Function_Reference/add_post_meta

    add_post_meta($post['ID'], 'field1', 'custom content');

    After much searching and trying to figure out how to code it myself (without any luck!) I found this old post which recommends using the ‘Custom Shortcodes’ plugin which automatically adds a custom field based on a custom field within the post.

    It’s an old plugin but I’ve just tested it on WP 4.0 and it works! Hurray!

    So now it’s a case of incorporating the shortcode in to the email that creates the postie post:

    [custom name=”field-name” value=”field-value”]

    Hope this helps anyone else looking for a solution to this.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Part of content to custom field’ is closed to new replies.