Support » Plugin: Form to Post » Shortcode in post meta form field

  • Resolved dadadesign


    Hi Michael,
    thank you very much for your excellent plugin! I’m using it with Contact Form 7.
    Do You see any way to put static text (shortcode) next to the field name, so that the Custom Fields Meta Box in WordPress Post Edit screen shows that text wrapped arround the input value?

    Any pointers are greatly appreciated!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Michael Simpson


    I don’t think I quite understand. I suppose you could name a field “[fieldname]” but I double CF7 will allow extra square brackets in its form field definitions.

    Michael, thank you very much for your super fast response!
    What I’m trying to do, is to transfer and display the star ratings users give in CF7 (via plugin Star Rating with font Awesome; field is set up as post meta) to/in the post they – thanks to your plugin – automatically create. Yet this delivers the pure numbers, say X from 0-5, of the rating. So I use a second plugin, which uses shortcodes to display star ratings in the post and enable my custom field to accept shortcode with “echo do_shortcode”. Now I’m hoping to find a solution to wrap the shortcode “[star rating=”X”]” around the number to display the stars of the rating in the post. Maybe this sounds a bit weird, but I’m not a coder.

    Plugin Author Michael Simpson


    Let me see if I understand.

    1. You have a CF7 Form. In it you have this star-rating fields.
    2. When a form is submitted, the F2P plugin creates a post
    3. You named the star-rating field “meta_” something so that F2P makes it a custom field on the post
    4. You want the post to automatically have [star rating=”X”] short code it it.
    5. That short code doesn’t read the custom field value, it just take a literal value like [star rating=”5″]. You want it to get the value from the custom field.

    And you don’t know how to do #4 or #5 or both?

    Michael, thank you again for your time and effort to structure my problem!
    To my understanding your description is perfectly right. I don’t know how to do #4 and #5. To put my goal in own words: I want the post to have automatically [star rating=”X”] short code in it, where X should be the numeric value from the custom field.

    Plugin Author Michael Simpson


    Let me see if I can simplify. I think this boils down to
    1. you have a field in a form that gives a number X
    2. you want to inject [star rating=”X”] in the post
    I’m assuming here that you don’t need to use a custom field.

    I propose this: We will set the value to something that F2P can pick up, and will add PHP filter code to set the short code in the post.

    1. Change the name of the star rating field in your form definition to “pinged”. This is a hack to get F2P to pick it up. That is a field is used to create a form, but we are going to hijack the name just to pass the value and grab it. (A limitation of my plugin that I should address at some point)

    2. Using Add Shortcodes Actions and Filters plugin, add a filter:

    function form_to_post_add_start_rating($post) {
        // get the start rating value
        $num = $post['pinged'];
        // remove phony pinged field
        unset( $post['pinged']);
        // Inject the shortcode at the beginning of the post contents
        $post['post_content'] = "[star rating=\"$num\"]" .   $post['post_content'];
        return $post;
    add_filter('form_to_post_before_create_post', 'form_to_post_add_start_rating');

    Michael, that’s it! I’m very happy with the solution you found.
    Thank you very very much for your time, effort and your great and super fast support! It was a real pleasure for me to make a donation. If it’s not too much to ask, I would like to come back to you, if I’ve got the rather unlikely need to use the short code in a custom field like in my first set up.

    Plugin Author Michael Simpson


    Feel free to ask. I’ll try to answer what I can.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Shortcode in post meta form field’ is closed to new replies.