• Resolved blakeow14

    (@blakeow14)


    I need help to make each form post to a specific category. The categories are already made within the post, whenever a user submits the form it creates a post in that category. So for example, I have 5 different CF7 forms, form 1 needs to post in category 1, form 2 needs to post in category 2, etc.

    Also I need all of the post to be published instead of going into draft. I used this snippet in my functions file. But it didn’t work. And I also noticed that this hook was specifically for that certain form. Is there a way to make all the forms to default to published?

    add_action( 'cf7_2_post_status_res101_copy', 'publish_new_res101_copy',10,3);
    /**
    * Function to change the post status of saved/submitted posts.
    * @param string $status the post status, default is 'draft'.
    * @param string $ckf7_key unique key to identify your form.
    * @param array $submitted_data complete set of data submitted in the form as an array of field-name=>value pairs.
    * @return string a valid post status ('publish'|'draft'|'pending'|'trash')
    */
    function publish_new_res101_copy($status, $ckf7_key, $submitted_data){
      /*The default behaviour is to save post to 'draft' status.  If you wish to change this, you can use this filter and return a valid post status: 'publish'|'draft'|'pending'|'trash'*/
      return 'publish';
    }
Viewing 1 replies (of 1 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    I have 5 different CF7 forms, form 1 needs to post in category 1, form 2 needs to post in category 2, etc.

    sure as long as all forms have the same fields which can be mapped to the common post then this is quite achievable. You’ll need to hook the action fired once the form is submitted (#6 in the helper list), ‘cf7_2_post_form_submitted_to_{$form-unique-key}’. This action will allow you to custom tag each submissions to the required category. You’ll need to map one action for each form.

    I need all of the post to be published instead of going into draft. I used this snippet in my functions file. But it didn’t work.

    this is probably because your filter function is never called. Note that the filter uses the form unique key in its nomenclature, hence if you change your form key, or design a new form your need to hook this filter again. The best is to use the helper links in the ‘Actions & Filters’ metabox on the bottom left of the map edit screen, the 2nd one under the section ‘Form Submitted hooks’.

    And I also noticed that this hook was specifically for that certain form. Is there a way to make all the forms to default to published?

    sure, use the same function and add one filter for each form, making sure the function call goes to the same unique function.

Viewing 1 replies (of 1 total)

The topic ‘Post Category & Publish Default’ is closed to new replies.