Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: telmo timeline
- Plugin URI:
- Description: escribe json
- Version: 1.0
- Author: Aitor Méndez
- Author URI: https//e451.net
- License: WTFPL – Do What the Fuck You Want to Public License
- */
- ?>
- <?php
- function create_timeline_json() {
- $posts_tl = get_posts(array(
- 'post_type' => array( 'post' ),
- 'posts_per_page' => '-1',
- 'post_status' => 'publish',
- ));
- $timeline = array(
- 'events' => [],
- );
- foreach ($posts_tl as $post) {
- $fecha_ok = new DateTime(get_field('fecha_conversacion', $post->ID, false));
- $anio = date_format($fecha_ok,"Y");
- $mes = date_format($fecha_ok,"m");
- $dia = date_format($fecha_ok,"d");
- $titulo = get_the_title($post->ID);
- $img_url = get_the_post_thumbnail_url($post->ID, 'merz-image');
- $media = array(
- "url" => $img_url,
- "caption" => " ",
- "credit" => " ",
- );
- $start_date = array(
- "month" => $mes,
- "day" => $dia,
- "year" => $anio,
- );
- $text = array(
- "headline" => $titulo,
- );
- $evento = array(
- "media" => $media,
- "start_date" => $start_date,
- "text" => $text,
- );
- $timeline[events][] = $evento;
- }
- wp_reset_postdata();
- $posts_tl = get_posts(array(
- 'post_type' => array( 'dialogos' ),
- 'posts_per_page' => '-1',
- 'post_status' => 'publish',
- ));
- foreach ($posts_tl as $post) {
- $fecha_ok = new DateTime(get_field('fecha_conversacion', $post->ID, false));
- $anio = date_format($fecha_ok,"Y");
- $mes = date_format($fecha_ok,"m");
- $dia = date_format($fecha_ok,"d");
- $titulo = get_the_title($post->ID);
- $texto = '<p>'.$post->post_content.'<p>';
- $start_date = array(
- "month" => $mes,
- "day" => $dia,
- "year" => $anio,
- );
- $text = array(
- "headline" => $titulo,
- "text" => $texto,
- );
- $evento = array(
- "start_date" => $start_date,
- "text" => $text,
- );
- $timeline[events][] = $evento;
- }
- wp_reset_postdata();
- $output =json_encode($timeline);
- $output_1 = str_replace("\\/","/",$output);
- $output_2 = str_replace("\\n\\n","</p><p>",$output_1);
- $output_3 = str_replace("\\n","<br/>",$output_2);
- $fp = fopen( ABSPATH . '../app/themes/sage/timeline.json', 'w' );
- fwrite( $fp, $output_3 );
- fclose( $fp );
- }
- add_action('save_post', __NAMESPACE__ . '\\create_timeline_json');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement