Title: Auto-Generate Posts
Last modified: August 31, 2016

---

# Auto-Generate Posts

 *  [masterrinks](https://wordpress.org/support/users/masterrinks/)
 * (@masterrinks)
 * [10 years ago](https://wordpress.org/support/topic/auto-generate-posts-1/)
 * Hey,
 * I have a theme that works pretty great for what I need. I just need a little 
   more functionality to it. I would say I’m a bit newer to wordpress as a programmer,
   but do have some previous php experience. I need to somehow auto-generate a post
   from a project post when said project post reaches completion. Generally when
   it is done it will have a Bar that reaches 100, turns green and says successful.
   When this happens I need for that to kick off a new post with certain data already
   built into it (user IDs who contributed only have access, etc.) so that the content
   that has been created has somewhere to go to be viewed. If I can’t do something
   like this it can spell a horrific amount of excess manual work in the future 
   for me. I attempted to insert it into the div and when that broke the page I 
   then attempted to do it in the functions.php thinking that I may be missing some
   order of operations that is specific to wordpress. Here’s the code I am attempting
   to use:
 * <?php
 * function newvid_create_post() {
 *  $post_id = -1;
 *  // Setup the author, slug, and title for the post
    $author_id = 1; $slug = ‘
   postingtest’; $title = ‘MySite Library Test’;
 *  // If the page doesn’t already exist, then create it
    if( null == get_page_by_title(
   $title ) ) {
 *  // Set the post ID
    $post_id = wp_insert_post( array( ‘comment_status’ => ‘closed’,‘
   ping_status’ => ‘closed’, ‘post_author’ => $author_id, ‘post_name’ => $post_id,‘
   post_title’ => $title, ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’ ) );
 *  // Otherwise, it’ll stop
    } else {
 *  // Using -2 to indicate that the page with the title already exists
    $post_id
   = -2;
 *  } // end if
 * } // newvid_create_post
    add_filter( ‘after_setup_theme’, ‘newvid_create_post’);
   The various calls to this function would look like this:
 * $post_id = newvid_create_post()
    if( -1 == $post_id || -2 == $post_id ) {
 * }
 * ?>
 * </div>
 * And for validation on those pages something like:
 * <?php $user_ID = get_current_user_id();
 * $query = “SELECT * FROM wp_posts WHERE ‘$user_ID’=’$post_author’ AND post_type
   =’project’ OR post_type=’funder’;
 * $result=mysqli->query($query);
 * $count=mysqli->_num_rows($result);
 * if(count==1){
 * echo “Access Granted.” // I want to put access to the actual media here
 * }
    else{
 * echo “No Access” // I am looking to put the redirect to the payment page for 
   access here which // will insert them into the table as a “funder”.
 * }
    ?>
 * If anyone has any thoughts at all or can point me in the right direction I would
   be really grateful.

The topic ‘Auto-Generate Posts’ is closed to new replies.

## Tags

 * [auto create](https://wordpress.org/support/topic-tag/auto-create/)
 * [auto-generate](https://wordpress.org/support/topic-tag/auto-generate/)
 * [automatically](https://wordpress.org/support/topic-tag/automatically/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [programmatically](https://wordpress.org/support/topic-tag/programmatically/)

 * 0 replies
 * 1 participant
 * Last reply from: [masterrinks](https://wordpress.org/support/users/masterrinks/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/auto-generate-posts-1/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
