• Hi everyone,

    I am writing a plugin and in the plugin I want to create a post in a custom post type with wp_insert_post and update_field(Advanced Custom Fields).
    The post gets added and shows in admin but not on the frontend.
    It only works when manually updating the post in admin.
    I allready tried adding visibility.

    This is my code:

    $reservering = array(
          'post_title'    => ''.time().'',
          'post_content'    => 'Reservering',
          'post_status'   => 'publish',
          'post_type'   => 'reserveringen',
          'post_author'    => 1
        );
    
        // Insert the post into the database
        $post_id = wp_insert_post( $reservering );
        update_post_meta( $post_id, '_visibility', 'visible' );
    
        $sloep = willekeurigBeschikbareBootOpLocatie($_POST['boekingsdatum'],$_POST['dagdeel'],$_POST['locaties']);
    
        update_field('dag', $_POST['boekingsdatum'], $post_id);
        update_field('dagdeel', $_POST['dagdeel'], $post_id);
        update_field('dagdeel_sloep', $sloep, $post_id);
        update_field('geslacht', $_POST['manvrouw'], $post_id);
        update_field('voornaam', $_POST['voornaam'], $post_id);
        update_field('achternaam', $_POST['achternaam'], $post_id);
        update_field('postcode', $_POST['postcode'], $post_id);
        update_field('plaats', $_POST['plaats'], $post_id);
        update_field('telefoon', $_POST['telefoon'], $post_id);

    I tried searching the internet, but all suggestions always point to visibility.

    I hope you guys have any idea what to do.

    Thanks,
    Rik

Viewing 1 replies (of 1 total)
  • Thread Starter rikdegraaf

    (@rikdegraaf)

    Nevermind, it had to do with updating the advanced custom fields.
    I updated them through field name, but it had to be done by field key.

Viewing 1 replies (of 1 total)

The topic ‘Add post through code, visibility on front end’ is closed to new replies.