| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
-
- // Allow [shortcode] in templates
- add_action( 'acf/init', 'set_acf_settings' );
- function set_acf_settings() {
- acf_update_setting( 'enable_shortcode', true );
- }
- add_filter( 'acf/shortcode/allow_in_block_themes_outside_content', '__return_true' );
-
- // Current Year [shortcode]
- function current_year_shortcode() {
- return date('Y');
- }
- add_shortcode( 'current_year', 'current_year_shortcode' );
-
-
- // General Settings - Set Default Featured Image Placeholder if none exists
- if ( ! class_exists( 'DefaultThumbnailID' ) ) {
- class DefaultThumbnailID {
- private static $instance;
- public function __construct() {
- // Add the option field to the General page.
- add_action( 'admin_init', array( &$this, 'show_default_thumbnail_id_option' ) );
- // Check if the default featured image exists.
- add_filter( 'has_post_thumbnail', array( &$this, 'set_has_post_thumbnail_value' ) );
- // Display the default featured image.
- add_filter( 'post_thumbnail_html', array( &$this, 'set_default_post_thumbnail_image' ), 10, 4 );
- }
- public static function get_instance() {
- if ( is_null( self::$instance ) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
- public function show_default_thumbnail_id_option() {
- register_setting(
- 'general', // General page
- '_default_thumbnail_id' // Option name
- );
- add_settings_field(
- 'default_thumbnail_id', // ID
- __( 'Default thumbnail ID', 'text-domain' ), // Option title
- array( &$this, 'display_input_field' ), // Display callback
- 'general', // General page
- 'default' // General page section
- );
- }
- public function display_input_field() {
- $value = get_option( '_default_thumbnail_id' );
- $value = wp_attachment_is_image( $value ) ? $value : '';
- ?>
- <input id="default_thumbnail_id" value="<?php echo esc_attr( $value ); ?>" name="_default_thumbnail_id"/>
- <?php
- }
- function set_has_post_thumbnail_value( $has_image ) {
- $default_thumbnail_id = get_option( '_default_thumbnail_id' );
- if ( ! empty( $default_thumbnail_id ) ) {
- $has_image = true;
- }
- return $has_image;
- }
- function set_default_post_thumbnail_image( $image, $post_id, $post_thumbnail_id, $size ) {
- $default_thumbnail_id = get_option( '_default_thumbnail_id' );
- if ( empty( $image ) && ! empty( $default_thumbnail_id ) ) {
- $image = wp_get_attachment_image( $default_thumbnail_id, $size );
- }
- return $image;
- }
- }
- // Instantiate the class object.
- DefaultThumbnailID::get_instance();
- }
-
-
- // Order by meta_key 'sortname' for post type 'artists'
- function my_pre_get_posts( $query ) {
- // do not modify queries in the admin
- if( is_admin() ) {
- return $query;
- }
- // only modify queries for 'artist' post type
- if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'artist' ) {
- $query->set('orderby', 'meta_value');
- $query->set('meta_key', 'sortname');
- $query->set('order', 'ASC');
- }
- // return
- return $query;
- }
- add_action('pre_get_posts', 'my_pre_get_posts');
-
-
- // Exclude Pages from Search Results
- function search_filter($query) {
- if ( ! is_admin() && $query->is_main_query() ) {
- if ( $query->is_search ) {
- $query->set( 'post_type', 'post' );
- }
- }
- }
- add_action( 'pre_get_posts', 'search_filter' );
-
-
- /**
- * This function modifies the main WordPress query to include an array of
- * post types instead of the default 'post' post type.
- * @param object $query The main WordPress query.
- */
- function include_custom_post_types_in_search_results( $query ) {
- if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
- $query->set( 'post_type', array( 'post', 'artist' ) );
- }
- }
- add_action( 'pre_get_posts', 'include_custom_post_types_in_search_results' );
|