Support

Account

Forum Replies Created

  • Hello,

    I am completely stupid :). The issue has been solved.
    I overlooked a function which had a return when a user is not logged in..

    add_action( 'get_header', 'tsm_do_acf_form_head', 1 );
    function tsm_do_acf_form_head() {
     // Bail if not logged in or not able to post
     if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
     return;
     }
     acf_form_head();
    }

    Thank you very much for your help, above code was the issue and I removed it.

  • Hello John,

    Actually yes, we have that.
    I even tried to take a clean code now, from the link you sent, and added post_author, but even that does not seem to work, we keep getting returned to the form when not logged in

    function my_pre_save_post( $post_id ) {
    
        // check if this is to be a new post
        if( $post_id != 'new' ) {
    
            return $post_id;
    
        }
    
        // Create a new post
        $post = array(
            'post_status'  => 'draft' ,
            'post_author' => '9',
            'post_title'  => 'A title, maybe a dadadada variable' ,
            'post_type'  => 'hufter' ,
        );  
    
        // insert the post
        $post_id = wp_insert_post( $post ); 
    
        // return the new ID
        return $post_id;
    
    }
    
    add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
    
  • Hello,

    Just letting you know, I also tried this code, which I took from the acf website:

    
    acf_form(array(
      'post_id'  => 'new_post',
      'post_title' => true,
      'post_content' => true,
      'new_post'  => array(
       'post_type'  => 'hufter',
       'post_author' => 9,
       'post_status' => 'publish'
      ),
      'return'  => home_url('contact-form-thank-you'),
      'submit_value' => 'Send'
     ));
    

    (hufter is the post_type we use)

    But even that is sending me back to the page I already am on, when I am not logged in, and when I am logged in; it does save the post but it does not assign it to the user (even though that user is set as admin so he can publish)

  • Hi @markbloomfield,

    Thanks for your reply. Unfortunately, I already tried it like that, and now again, but it still fails when a user is not logged in.

    I get redirected back to the same page I already am on as soon as I use post_author in the array.

    `<?php

    $new_post = array(
    ‘post_id’ => ‘new’,
    ‘post_author’ => ‘9’,
    ‘field_groups’ => array(2023,2028),
    ‘form’ => true,
    ‘return’ => ‘%post_url%’, // Redirect to new post url
    ‘html_before_fields’ => ”,
    ‘html_after_fields’ => ”,
    ‘submit_value’ => ‘Melding plaatsen’,
    ‘updated_message’ => ‘Melding geplaatst!’
    );
    acf_form( $new_post );

    ?>

Viewing 4 posts - 1 through 4 (of 4 total)