Advertisement
Guest User

Create posts ans assign term Wordpress - testing

a guest
Dec 16th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2.  
  3. // TO DO WHEN THEME IS ACTIVATED ///////////////////////
  4. if (isset($_GET['activated']) && is_admin()){
  5.  
  6. function create_frontles_posts() {
  7.   $x = 1;
  8.  
  9.   do {
  10.         //creating a blank array to store the inserted terms ids
  11.         $terms = array();
  12.         $tax_insert_id = wp_insert_term('mosaic-home','tiles_categories' );
  13.         $terms[] = $tax_insert_id['term_id'];
  14.  
  15.         //Creating a post array
  16.         $post = array(
  17.                 'comment_status'  =>  'closed',
  18.                 'ping_status'   =>  'closed',
  19.                 'post_author'   =>  1,
  20.                 'post_name'   =>  'tile'.$x,
  21.                 'post_title'    =>  'Tile',
  22.                 'post_status'   =>  'publish',
  23.                 'post_type'   =>  'frontiles',
  24.         );
  25.  
  26.         //Inserting the post in WordPress using wp_insert_post()
  27.         //if the post is successfully posted, post_id is returned and stored in $the_post_id
  28.         $the_post_id = wp_insert_post( $post );
  29.  
  30.         //assign the terms stored in $terms array to $the_post_id post
  31.         wp_set_post_terms( $the_post_id, $terms, 'tiles_categories' );
  32.  
  33.     $x++;
  34.   } while ($x <= 24);
  35. }
  36.  
  37.  
  38. function programmatically_create_post() {
  39.  
  40.   // Initialize the page ID to -1. This indicates no action has been taken.
  41.   $post_id = -1;
  42.   $title=' ';
  43.   // If the page doesn't already exist, then create it
  44.   if( null == get_page_by_title( $title ) ) {
  45.       create_frontles_posts();
  46.       } else {
  47.             // Otherwise, we'll stop
  48.             $post_id = -2;
  49.     }
  50. }
  51. add_filter( 'after_setup_theme', 'programmatically_create_post' );
  52.  
  53.  
  54. } // end action on activation theme
  55.  
  56.  
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement