0 ) { // Set URL and Title for Category. $category_title = sprintf( esc_html__( 'View all posts from category %s', 'beetle' ), get_cat_name( $category_id ) ); $category_url = get_category_link( $category_id ); // Set Widget Title with link to category archive. $widget_title = '' . $widget_title . ''; } return $widget_title; } endif; if ( ! function_exists( 'beetle_magazine_entry_meta' ) ) : /** * Displays the date and author of magazine posts */ function beetle_magazine_entry_meta() { $postmeta = beetle_meta_date(); $postmeta .= beetle_meta_author(); echo '
' . $postmeta . '
'; } endif; if ( ! function_exists( 'beetle_magazine_entry_date' ) ) : /** * Displays the date of magazine posts */ function beetle_magazine_entry_date() { echo '
' . beetle_meta_date() . '
'; } endif; /** * Function to change excerpt length for posts in category posts widgets * * @param int $length Length of excerpt in number of words. * @return int */ function beetle_magazine_posts_excerpt_length( $length ) { return 15; } /** * Get Magazine Post IDs * * @param String $cache_id Magazine Widget Instance. * @param int $category Category ID. * @param int $number_of_posts Number of posts. * @return array Post IDs */ function beetle_get_magazine_post_ids( $cache_id, $category, $number_of_posts ) { $cache_id = sanitize_key( $cache_id ); $post_ids = get_transient( 'beetle_magazine_post_ids' ); if ( ! isset( $post_ids[ $cache_id ] ) ) { // Get Posts from Database. $query_arguments = array( 'fields' => 'ids', 'cat' => (int) $category, 'posts_per_page' => (int) $number_of_posts, 'ignore_sticky_posts' => true, 'no_found_rows' => true, ); $query = new WP_Query( $query_arguments ); // Create an array of all post ids. $post_ids[ $cache_id ] = $query->posts; // Set Transient. set_transient( 'beetle_magazine_post_ids', $post_ids ); } return apply_filters( 'beetle_magazine_post_ids', $post_ids[ $cache_id ], $cache_id ); } /** * Delete Cached Post IDs * * @return void */ function beetle_flush_magazine_post_ids() { delete_transient( 'beetle_magazine_post_ids' ); } add_action( 'save_post', 'beetle_flush_magazine_post_ids' ); add_action( 'deleted_post', 'beetle_flush_magazine_post_ids' ); add_action( 'customize_save_after', 'beetle_flush_magazine_post_ids' ); add_action( 'switch_theme', 'beetle_flush_magazine_post_ids' );