Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // display table on person page
- function render_person_data( $atts ) {
- $atts = shortcode_atts( array(
- 'child_id' => '',
- ), $atts );
- $child_id = intval( $atts['child_id'] );
- if ( ! $child_id ) {
- return '<strong>No child ID provided</strong>';
- }
- $current_person_data = get_post_meta( $child_id, 'person_data', true );
- if ( empty( $current_person_data ) ) {
- return '<strong>No items found</strong>';
- }
- // Сортируем данные по полю 'first_air_date' в порядке убывания
- usort( $current_person_data, function( $a, $b ) {
- $first_air_date_a = get_post_meta( $a['parent_id'], 'wpcf-first-air-date', true );
- $first_air_date_b = get_post_meta( $b['parent_id'], 'wpcf-first-air-date', true );
- return $first_air_date_b - $first_air_date_a; // Сортировка по убыванию
- });
- ob_start();
- ?>
- <table width="100%" class="people-credits-table">
- <thead>
- <tr>
- <th>Title</th>
- <th class="type">Type</th>
- <th>Release Date</th>
- </tr>
- </thead>
- <tbody class="wpv-loop js-wpv-loop">
- <?php foreach ( $current_person_data as $person_data ) :
- $parent_id = $person_data['parent_id'];
- $intermediary_id = $person_data['intermediary_id'];
- $relation = $person_data['relation'];
- if ( in_array( $relation, array( 'cast', 'cast-movie', 'cast-special' ) ) ) {
- $relation_type = get_post_type( $parent_id );
- } elseif ( in_array( $relation, array( 'crew-drama', 'crew-movie', 'crew-special' ) ) ) {
- $relation_type = 'crew';
- } else {
- continue;
- }
- $parent_title = get_the_title( $parent_id );
- $parent_link = get_permalink( $parent_id );
- $parent_type = get_post_type( $parent_id );
- $featured_image = get_the_post_thumbnail( $parent_id, 'thumbnail' );
- $first_air_date = get_post_meta( $parent_id, 'wpcf-first-air-date', true );
- $average_rating = get_post_meta( $parent_id, 'wpcf-average-rating', true );
- $country_terms = get_the_terms( $parent_id, 'country' );
- $country_slug = $country_terms ? $country_terms[0]->slug : '';
- $country_name = $country_terms ? $country_terms[0]->name : '';
- $country_link = $country_terms ? get_term_link( $country_terms[0] ) : '';
- $role = get_post_meta( $intermediary_id, 'wpcf-role', true );
- $role_importance = types_render_field( "role-importance", array( "item" => $intermediary_id ) );
- $credits = types_render_field( "credits", array( "separator" => ", ", "item" => $intermediary_id ) );
- ?>
- <tr data-type="<?php echo esc_attr( $relation_type ); ?>" data-timestamp="<?php echo esc_attr( $first_air_date ); ?>" data-title="<?php echo esc_attr( $parent_title ); ?>">
- <td>
- <div class="d-flex">
- <div class="item-img"><?php echo $featured_image; ?></div>
- <div class="item-info">
- <a href="<?php echo esc_url( $parent_link ); ?>"><?php echo esc_html( $parent_title ); ?></a>
- <ul class="bycategories d-flex flex-wrap align-items-center">
- <?php if ( !empty( $average_rating ) ) : ?>
- <li style="font-size:13px;margin:0 5px 5px">
- <i class="fas fa-star"></i> <?php echo esc_html( $average_rating ); ?>
- </li>
- <?php endif; ?>
- <li>
- <span class="sp-badge <?php echo esc_attr( $country_slug ); ?>">
- <a href="<?php echo esc_url( $country_link ); ?>"><?php echo esc_html( $country_name ); ?></a>
- </span>
- </li>
- <li style="margin-bottom:5px;width:100%;">
- <?php echo esc_html( $role_importance ); ?>
- <?php echo esc_html( $credits ); ?>
- <?php echo !empty( $role ) ? ': ' . esc_html( $role ) : ''; ?>
- </li>
- </ul>
- </div>
- </div>
- </td>
- <td class="type">
- <div class="p-type <?php echo esc_attr( $parent_type ); ?>" style="padding:3.3px 5px;margin:0 5px 5px 0">
- <i class="fas"></i> <?php echo esc_html( $parent_type ); ?>
- </div>
- </td>
- <td><?php echo date( 'M j, Y', $first_air_date ); ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php
- return ob_get_clean();
- }
- add_shortcode( 'person-data', 'render_person_data' );
Advertisement
Add Comment
Please, Sign In to add comment