Saturday 4 February 2023

Create Elementor duplicate pages with different name .

  $csvdata = csv_to_array('../city.csv');

foreach($csvdata as $key=>$csvrow){

if($key==1){

$postidd = get_post(13); 

$frontend = new \Elementor\Frontend();

$pagecontentorg = $frontend->get_builder_content_for_display( 13, $with_css = true );

//apply_filters('the_content', $postidd->post_content); 

$pagecontent = str_replace("problèmes",$csvrow['city'],$pagecontentorg); 

  $post_details = array(

  'post_title'    => 'testing page 5',

  'post_content'  =>$pagecontent,

  'post_status'   => 'publish',

  'post_author'   => 1,

  'post_type' => 'page',

  'page_template'  => 'elementor_header_footer'

   );

   wp_insert_post( $post_details );

/*echo '<pre>';

print_r($csvrow['city']);

echo '</pre>';*/

}

Friday 3 February 2023

Create duplicate pages with different name .

 $postidd = get_post(2457); 

$pagecontent = apply_filters('the_content', $postidd->post_content); 


  /*$post_details = array(

  'post_title'    => 'manjeet page',

  'post_content'  => $pagecontent,

  'post_status'   => 'publish',

  'post_author'   => 1,

  'post_type' => 'page'

   );

   wp_insert_post( $post_details );*/


function csv_to_array($filename='', $delimiter=',')

{

    if(!file_exists($filename) || !is_readable($filename))

        return FALSE;


    $header = NULL;

    $data = array();

    if (($handle = fopen($filename, 'r')) !== FALSE)

    {

        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)

        {

            if(!$header)

                $header = $row;

            else

                $data[] = array_combine($header, $row);

        }

        fclose($handle);

    }

    return $data;

}


$csvdata = csv_to_array('../city.csv');

foreach($csvdata as $csvrow){

echo '<pre>';

print_r($csvrow['city']);

echo '</pre>';

}

Deletes all posts from "products" custom post type.

 /**

* Deletes all posts from "products" custom post type. */ function wpdocs_delete_all_products() { $myproducts = get_pages( array( 'post_type' => 'products') ); foreach ( $myproducts as $myproduct ) { // Delete all products. wp_delete_post( $myproduct->ID, true); // Set to False if you want to send them to Trash. } } add_action( 'init', 'wpdocs_delete_all_products' );