Come creare un feed prodotti quando non hai un Woocommerce installato

Come Creare Un Feed Prodotti Quando Non Hai Un Woocommerce Installato

In questo caso dovevo dare a Doofinder un feed per il custom post type Prodotti (quindi chi ha sviluppato il sito non ha usato Woocommerce, poco male) per la ricerca avanzata che crea Doofinder.
Qui il “problema” fondamentale è che dovevo creare un feed per lingua e le lingue erano davvero tante.
Questo script mi ha aiutato a fare quello che avevo bisogno.
Chiaramente va messo sotto cron job in questo modo si aggiornerà di volta in volta.

error_reporting(E_ALL);
ini_set('display_errors', 1);

	function find_wordpress_base_path() {
		$dir = dirname(__FILE__);
		do {
			//it is possible to check for other files here
			if( file_exists($dir."/wp-config.php") ) {
				return $dir;
			}
		} while( $dir = realpath("$dir/..") );
		return null;
	}
	
	/* Import media from url
 *
 * @param string $file_url URL of the existing file from the original site
 * @param int $post_id The post ID of the post to which the imported media is to be attached
 *
 * @return boolean True on success, false on failure
 */


	define( 'BASE_PATH', find_wordpress_base_path()."/" );
	define('WP_USE_THEMES', false);
	global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
	require(BASE_PATH . 'wp-load.php');

    global $wpdb,$sitepress;
	
	$i=0;
	$columns = array(
        'id',
        'Titolo',
		'Immagine',
        'Sottotitolo',
        'Designer',
        'Categoria',
		'Link',
    );
	
    $languages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' );
    if ( !empty( $languages ) ) {
        foreach( $languages as $l ) {
            //if ( $l['active'] ) {
				$sitepress->switch_lang( $l['language_code'] );
				echo $l['language_code'].'<br>';
					$fp=fopen ('prodotti_'.$l['language_code'].'.csv','w');
					//$line=implode(',', $columns).'\n';
					fputcsv($fp, $columns);
					$the_query = new WP_Query(
						  array(
						   'post_type'      => 'prodotti',
						   'post_status' => 'pubblish',
						   'posts_per_page' => -1,
						   'suppress_filters' => false,
						  )
						);
					while ( $the_query->have_posts() ) : $the_query->the_post(); 
						$i++;
						$terms=array();
						$category='';
						$terms=get_the_terms( $post->ID, 'categorie_prodotto' );
						if(is_array($terms)){
							foreach($terms as $term){
								$category.=$term->name.' > ';
							}
						}
						$sottotitolo=get_post_meta(get_the_ID(), 'sottotitolo', TRUE);
						$designer=get_post_meta(get_the_ID(), 'designer', TRUE);
						$permalink=get_permalink();
						//$line=get_the_ID().','.get_the_title().','.$category.','.$sectorw.','.$brand->name.','.$dia.','.$riferimento.','.$diamm.','.$permalink.'\n';
						$row = array(
							get_the_ID(),
							str_replace(' ',' ',get_the_title()),
							get_the_post_thumbnail_url(get_the_ID(),'full'),
							substr($sottotitolo,0,-2),
							substr($designer,0,-2),
							substr($category,0,-2),
							$permalink,
						);
						fputcsv($fp, $row);

					
						//echo $i.' - '.get_the_title()."<br>";
					endwhile;
					fclose($fp);
			//}
        }
    }

Hai un problema con il web?

Il tuo sito internet non vuole funzionare?

Vuoi rinnovarlo o sistemarlo?

Hai un’idea di integrazione ma non sai se è possibile realizzarla o meno?

    Accetto la Privacy Policy
    Autorizzo al trattamento dei miei dati personali, per ricevere le informazioni richieste attraverso questo modulo di contatto. I dati da te inseriti attraverso questo modulo verranno utilizzati solo per essere da me ricontattato.

    Recensioni

    Scrivimi una recensione

    Questo QR Code ti permette di lasciarmi una recensione in maniera facile e veloce.

    Altrimenti qui sotto ti lascio un bottone, con il quale puoi lasciare la recensione direttamente su Google My Business.

    Lascia una recensione su Google