Advertisement
verygoodplugins

Untitled

Jan 28th, 2020
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1.         $crm_names = array();
  2.         $posts     = array();
  3.  
  4.         $crms = get_field( 'crms', 'option' );
  5.  
  6.         foreach ( $crms as $crm ) {
  7.  
  8.             $crm_names[] = $crm['name'];
  9.  
  10.         }
  11.  
  12.         $args = array(
  13.             'nopaging'  => true,
  14.             'post_type' => 'documentation',
  15.             'tax_query' => array(
  16.                 array(
  17.                     'taxonomy' => 'documentation_category',
  18.                     'field'    => 'slug',
  19.                     'terms'    => 'integrations',
  20.                 ),
  21.             ),
  22.         );
  23.  
  24.         $integrations = get_posts( $args );
  25.  
  26.         $did = 0;
  27.  
  28.         foreach ( $crm_names as $crm_name ) {
  29.  
  30.             foreach ( $integrations as $integration ) {
  31.  
  32.                 $title = 'Connect ' . $integration->post_title . ' to ' . $crm_name;
  33.  
  34.                 if ( ! empty( get_page_by_title( $title, OBJECT, 'connect' ) ) ) {
  35.                     continue;
  36.                 }
  37.  
  38.                 $args = array(
  39.                     'post_title'  => $title,
  40.                     'post_status' => 'publish',
  41.                     'post_type'   => 'connect',
  42.                 );
  43.  
  44.                 $post_id = wp_insert_post( $args );
  45.  
  46.                 update_post_meta( $post_id, 'crm_name', $crm_name );
  47.                 update_post_meta( $post_id, 'plugin_name', $integration->post_title );
  48.                 update_post_meta( $post_id, 'plugin_docs_id', $integration->ID );
  49.  
  50.                 $did++;
  51.  
  52.             }
  53.         }
  54.  
  55.         echo 'Did ' . $did;
  56.  
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement