Plugin Directory

Changeset 2024626


Ignore:
Timestamp:
02/04/2019 01:46:18 PM (7 years ago)
Author:
nikolam
Message:

Improve latest_series shortcode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sermon-manager-for-wordpress/trunk/includes/class-sm-shortcodes.php

    r2024621 r2024626  
    615615
    616616    /**
    617      * Get all sermon series as WP_Term object.
    618      *
    619      * @param int $latest_sermon Optional. Latest sermon ID. If not provided, it will try to get it automatically.
    620      * @param int $service_type  Optional. Service Type for getting latest sermon ID.
    621      *
    622      * @return WP_Term|null
    623      */
    624     public function get_latest_series_with_image( $latest_sermon = 0, $service_type = 0 ) {
    625         if ( empty( $latest_sermon ) ) {
    626             $latest_sermon = $this->get_latest_sermon_id( $service_type );
    627         }
    628 
    629         $latest_series = get_the_terms( $latest_sermon, 'wpfc_sermon_series' );
    630 
    631         foreach ( $latest_series as $series ) {
    632             if ( $this->get_latest_series_image_id( $series ) ) {
    633                 return $series;
    634             }
    635         }
    636 
    637         return is_array( $latest_series ) && count( $latest_series ) > 0 ? false : null;
     617     * Get latest sermon series that has an image.
     618     *
     619     * @return WP_Term|null|false Term if found, null if there are no terms, false if there is no term with image.
     620     */
     621    public function get_latest_series_with_image() {
     622        $series = get_terms(
     623            array(
     624                'taxonomy'     => 'wpfc_sermon_series',
     625                'hide_empty'   => false,
     626                'orderby'      => 'meta_value_num',
     627                'order'        => 'DESC',
     628                'meta_key'     => 'sermon_date',
     629                'meta_value'   => time(),
     630                'meta_compare' => '<=',
     631            )
     632        );
     633
     634        // Fallback to next one until we find the one that has an image.
     635        foreach ( $series as $serie ) {
     636            if ( $this->get_latest_series_image_id( $serie ) ) {
     637                return $serie;
     638            }
     639        }
     640
     641        return is_array( $series ) && count( $series ) > 0 ? false : null;
    638642    }
    639643
     
    789793            'hide_preachers'     => '',
    790794            'hide_books'         => '',
    791             'hide_dates'          => '',
     795            'hide_dates'         => '',
    792796            'include'            => '',
    793797            'exclude'            => '',
     
    824828            'hide_books'         => $args['hide_books'],
    825829            'hide_service_types' => $args['hide_service_types'],
    826             'hide_dates'         => $args['hide_dates'],
     830            'hide_dates'         => $args['hide_dates'],
    827831        );
    828832
     
    11111115            'hide_books'            => '',
    11121116            'hide_service_types'    => \SermonManager::getOption( 'service_type_filtering' ) ? '' : 'yes',
    1113             'hide_dates'            => '',
     1117            'hide_dates'            => '',
    11141118            'action'                => 'none',
    11151119            'smp_override_settings' => true,
Note: See TracChangeset for help on using the changeset viewer.