Forum Replies Created

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

    (@energy2k)

    Hello!

    I already gave this an impossible and I’ve been programming in PHP directly against wordpress.

    If this helps you, the simple code is this:

    // --------------------------
    // WordPress Init.
    // --------------------------
    
    define('WP_USE_THEMES', false);
    require($_SERVER['DOCUMENT_ROOT'] . 'wp-blog-header.php');
    
    $user = wp_authenticate('myUser', 'myPass');
    
    // --------------------------
    // WordPress Post.
    // --------------------------
    
    $body = array(
                'post_title' => 'My Cool Title',
                'post_content' => '',
                'post_status' => 'publish',
                'post_type' => 'movies',
                'post_name' => 'my-cool-title',
                'post_author' => get_current_user_id(),
                'meta_input' => array(
                    'movies_length' => '94',
                    'event_country' => 'USA',
                    'event_year' => '2016'
                )
            );
    
        $post_id = wp_insert_post($body, true);
    
        if (is_wp_error($post_id)) {
            echo('Can't Create: ' . $post_id->get_error_message());
            echo "<br />";
        } else {
            echo('Created! ID: ' . $post_id);
            echo "<br />";
        }

Viewing 1 replies (of 1 total)