Skip to main content
Line up all the indents - the suggested edit didn't go far enough
Source Link
Rup
  • 4.4k
  • 4
  • 28
  • 29

wp_insert_post not intertinginserting post from XML

add_action('import_demo', 'importIt');
function importIt(){
    // The code until now
    $path = get_template_directory() . '/demo/pages.xml';
    $xml = simplexml_load_file($path);
    foreach ($xml->channel->item as $item) {
        $postCreated = array(
            'post_title'    => $item->title,
            'post_content'  => $item->content,
    //      'post_excerpt'  => $item->excerpt,
            'post_status'   => 'publish',
            'post_type'     => 'page', // Or "page" or some custom post type
        );
        
      $postInsertId = wp_insert_post( $postCreated );
    
      add_action('add_attachment','featuredImageTrick');
      media_sideload_image($item->image, $postInsertId, $item->title);
      remove_action('add_attachment','featuredImageTrick');

  function featuredImageTrick($att_id){
     $p = get_post($att_id);
  
     update_post_meta($p->post_parent,'_thumbnail_id',$att_id);
  }
 }
}
add_action('import_demo', 'importIt');
function importIt(){
    // The code until now
    $path = get_template_directory() . '/demo/pages.xml';
    $xml = simplexml_load_file($path);
    foreach ($xml->channel->item as $item) {
        $postCreated = array(
            'post_title'    => $item->title,
            'post_content'  => $item->content,
            // 'post_excerpt'  => $item->excerpt,
            'post_status'   => 'publish',
            'post_type'     => 'page', // Or "page" or some custom post type
        );

        $postInsertId = wp_insert_post( $postCreated );

        add_action('add_attachment','featuredImageTrick');
        media_sideload_image($item->image, $postInsertId, $item->title);
        remove_action('add_attachment','featuredImageTrick');

        function featuredImageTrick($att_id){
            $p = get_post($att_id);

            update_post_meta($p->post_parent,'_thumbnail_id',$att_id);
        }
    }
}

wp_insert_post not interting post from XML

add_action('import_demo', 'importIt');
function importIt(){
    // The code until now
    $path = get_template_directory() . '/demo/pages.xml';
    $xml = simplexml_load_file($path);
    foreach ($xml->channel->item as $item) {
        $postCreated = array(
            'post_title'    => $item->title,
            'post_content'  => $item->content,
    //      'post_excerpt'  => $item->excerpt,
            'post_status'   => 'publish',
            'post_type'     => 'page', // Or "page" or some custom post type
        );
        
      $postInsertId = wp_insert_post( $postCreated );
    
      add_action('add_attachment','featuredImageTrick');
      media_sideload_image($item->image, $postInsertId, $item->title);
      remove_action('add_attachment','featuredImageTrick');

  function featuredImageTrick($att_id){
     $p = get_post($att_id);
  
     update_post_meta($p->post_parent,'_thumbnail_id',$att_id);
  }
 }
}

wp_insert_post not inserting post from XML

add_action('import_demo', 'importIt');
function importIt(){
    // The code until now
    $path = get_template_directory() . '/demo/pages.xml';
    $xml = simplexml_load_file($path);
    foreach ($xml->channel->item as $item) {
        $postCreated = array(
            'post_title'    => $item->title,
            'post_content'  => $item->content,
            // 'post_excerpt'  => $item->excerpt,
            'post_status'   => 'publish',
            'post_type'     => 'page', // Or "page" or some custom post type
        );

        $postInsertId = wp_insert_post( $postCreated );

        add_action('add_attachment','featuredImageTrick');
        media_sideload_image($item->image, $postInsertId, $item->title);
        remove_action('add_attachment','featuredImageTrick');

        function featuredImageTrick($att_id){
            $p = get_post($att_id);

            update_post_meta($p->post_parent,'_thumbnail_id',$att_id);
        }
    }
}

I'm using below to read XML file and import its content as a page in wordpress, but it's not working:

add_action('import_demo', 'importIt');
function importIt(){
    // The code until now
    $path = get_template_directory() . '/demo/pages.xml';
    $xml = simplexml_load_file($path);
    foreach ($xml->channel->item as $item) {
        $postCreated = array(
            'post_title'    => $item->title,
            'post_content'  => $item->content,
    //      'post_excerpt'  => $item->excerpt,
            'post_status'   => 'publish',
            'post_type'     => 'page', // Or "page" or some custom post type
        );
        
        $postInsertId = wp_insert_post( $postCreated );
 
    
  
    
    add_action('add_attachment','featuredImageTrick');
      media_sideload_image($item->image, $postInsertId, $item->title);
      remove_action('add_attachment','featuredImageTrick'); 

  function featuredImageTrick($att_id){
     $p = get_post($att_id);
  
     update_post_meta($p->post_parent,'_thumbnail_id',$att_id);
  }
 }
}

I'm using below to read XML file and import its content as a page in wordpress, but it's not working:

add_action('import_demo', 'importIt');
function importIt(){
    // The code until now
    $path = get_template_directory() . '/demo/pages.xml';
    $xml = simplexml_load_file($path);
    foreach ($xml->channel->item as $item) {
        $postCreated = array(
            'post_title'    => $item->title,
            'post_content'  => $item->content,
    //      'post_excerpt'  => $item->excerpt,
            'post_status'   => 'publish',
            'post_type'     => 'page', // Or "page" or some custom post type
        );
        
        $postInsertId = wp_insert_post( $postCreated );
 
    
  
    
    add_action('add_attachment','featuredImageTrick');
media_sideload_image($item->image, $postInsertId, $item->title);
remove_action('add_attachment','featuredImageTrick');
function featuredImageTrick($att_id){
    $p = get_post($att_id);
  
    update_post_meta($p->post_parent,'_thumbnail_id',$att_id);
}
}
}

I'm using below to read XML file and import its content as a page in wordpress, but it's not working:

add_action('import_demo', 'importIt');
function importIt(){
    // The code until now
    $path = get_template_directory() . '/demo/pages.xml';
    $xml = simplexml_load_file($path);
    foreach ($xml->channel->item as $item) {
        $postCreated = array(
            'post_title'    => $item->title,
            'post_content'  => $item->content,
    //      'post_excerpt'  => $item->excerpt,
            'post_status'   => 'publish',
            'post_type'     => 'page', // Or "page" or some custom post type
        );
        
      $postInsertId = wp_insert_post( $postCreated );
    
      add_action('add_attachment','featuredImageTrick');
      media_sideload_image($item->image, $postInsertId, $item->title);
      remove_action('add_attachment','featuredImageTrick'); 

  function featuredImageTrick($att_id){
     $p = get_post($att_id);
  
     update_post_meta($p->post_parent,'_thumbnail_id',$att_id);
  }
 }
}
Source Link

wp_insert_post not interting post from XML

I'm using below to read XML file and import its content as a page in wordpress, but it's not working:

add_action('import_demo', 'importIt');
function importIt(){
    // The code until now
    $path = get_template_directory() . '/demo/pages.xml';
    $xml = simplexml_load_file($path);
    foreach ($xml->channel->item as $item) {
        $postCreated = array(
            'post_title'    => $item->title,
            'post_content'  => $item->content,
    //      'post_excerpt'  => $item->excerpt,
            'post_status'   => 'publish',
            'post_type'     => 'page', // Or "page" or some custom post type
        );
        
        $postInsertId = wp_insert_post( $postCreated );

    
  
    
    add_action('add_attachment','featuredImageTrick');
media_sideload_image($item->image, $postInsertId, $item->title);
remove_action('add_attachment','featuredImageTrick');
function featuredImageTrick($att_id){
    $p = get_post($att_id);
  
    update_post_meta($p->post_parent,'_thumbnail_id',$att_id);
}
}
}