• Resolved gremelle

    (@gremelle)


    I really appreciate the work your doing with Contact Forms 7.

    It really is a great help to have a GPL release plugin that does what this plug in do.

    I ready through the Filters & Actions section of the plugin page.

    for creating publish posts, and not drafts, it is said in the example:

    add_action(‘cf7_2_post_form_mapped_to_my-cpt’,’modify_form_posts’,10,2);
    function modify_form_posts($post_id, $cf7_form_data){
    //cf7_form_data is the submitted data from your form
    //post_id is the id of the post to which it has been saved.
    //… do something here
    }

    should i just add wp_publish_post() inside the modify_form_posts function?

    Thanks again for your awesome plugin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    Hello gremelle

    I really appreciate the work your doing with Contact Forms 7.
    It really is a great help to have a GPL release plugin that does what this plug in do.

    ?? thank you for your encouragement. This is one of the main reasons why I build these plugins.

    You have the correct action hook, but you should use the wp_post_update function.

    
    $args = array(
    'ID' => $post_id,
    'post_status' => 'publish'
    );
    wp_update_post($args);
    
    webwhalenl

    (@webwhalenl)

    Dear Aurovrata,

    I’m not very experienced with hooks in WordPress. I also would like to have the new posts published immediately, without first being posted as drafts. If I understand it correctly, from the above messages, the following code needs to be added:

    /**
     * Custom code for instant publishing
     */
    
    add_action(‘cf7_2_post_form_mapped_to_my-cpt’,’modify_form_posts’,10,2);
    function modify_form_posts($post_id, $cf7_form_data){
    //cf7_form_data is the submitted data from your form
    //post_id is the id of the post to which it has been saved.
    $args = array(
    'ID' => $post_id,
    'post_status' => 'publish'
    );
    wp_update_post($args);
    }

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

    Where do I have to add this code, though?

    Many thanks for helping out!

    Best regards,

    Max de Feber

    • This reply was modified 8 years ago by bdbrown.
    • This reply was modified 8 years ago by bdbrown.
    Plugin Author Aurovrata Venet

    (@aurovrata)

    this code should be in your functions.php file.

    Max, please post your issues in a separate thread, so others can also find the problem and see the solution.

    webwhalenl

    (@webwhalenl)

    Dear Aurovrata,

    Many thanks for your quick reply. I have put that exact piece of code on the bottom of my theme’s functions.php file, however the new posts still appear as drafts.

    Any idea what goes wrong here?

    Best regards,

    Max de Feber

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get Posts to publish’ is closed to new replies.