true ), 'objects' ); foreach ( $post_types as $post_type ) { if ( 'attachment' === $post_type->name ) { continue; } $options[ $post_type->name ] = $post_type->label; } } if ( empty( $options ) ) { $options = array( 'post' => esc_html__( 'Post', 'advance-elementor-slider' ) ); } self::$cache['post_types'] = $options; return $options; } /** * Terms of every public taxonomy, labelled with their taxonomy. * * Keys are "taxonomy:term_id" so a single control can mix taxonomies. * * @return array */ public static function get_taxonomy_terms() { if ( isset( self::$cache['terms'] ) ) { return self::$cache['terms']; } $options = array(); if ( self::is_panel_request() ) { $taxonomies = get_taxonomies( array( 'public' => true ), 'objects' ); foreach ( $taxonomies as $taxonomy ) { $terms = get_terms( array( 'taxonomy' => $taxonomy->name, 'hide_empty' => false, 'number' => 200, ) ); if ( is_wp_error( $terms ) || empty( $terms ) ) { continue; } foreach ( $terms as $term ) { $options[ $taxonomy->name . ':' . $term->term_id ] = $taxonomy->labels->singular_name . ': ' . $term->name; } } } self::$cache['terms'] = $options; return $options; } /** * Turn the widget's query controls into WP_Query arguments. * * @param array $settings Widget settings. * @return array */ public static function build_query_args( array $settings ) { $post_type = ! empty( $settings['post_type'] ) ? $settings['post_type'] : 'post'; $per_page = isset( $settings['posts_per_page'] ) ? absint( $settings['posts_per_page'] ) : 6; $args = array( 'post_type' => $post_type, 'posts_per_page' => $per_page > 0 ? $per_page : 6, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'orderby' => ! empty( $settings['orderby'] ) ? $settings['orderby'] : 'date', 'order' => ! empty( $settings['order'] ) ? $settings['order'] : 'DESC', 'offset' => isset( $settings['offset'] ) ? absint( $settings['offset'] ) : 0, 'no_found_rows' => true, ); if ( ! empty( $settings['include_terms'] ) && is_array( $settings['include_terms'] ) ) { $tax_query = array( 'relation' => 'AND' ); $grouped = array(); foreach ( $settings['include_terms'] as $value ) { $parts = explode( ':', $value ); if ( 2 !== count( $parts ) ) { continue; } $grouped[ $parts[0] ][] = absint( $parts[1] ); } foreach ( $grouped as $taxonomy => $term_ids ) { $tax_query[] = array( 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $term_ids, ); } if ( count( $tax_query ) > 1 ) { $args['tax_query'] = $tax_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query } } if ( ! empty( $settings['exclude_current'] ) && 'yes' === $settings['exclude_current'] && is_singular() ) { $args['post__not_in'] = array( get_the_ID() ); } return $args; } /** * Trim text to a word count. * * @param string $text Source text. * @param int $words Word limit. * @return string */ public static function trim_words( $text, $words ) { $words = absint( $words ); if ( ! $words ) { return ''; } return wp_trim_words( wp_strip_all_tags( $text ), $words, '…' ); } }