WordPress.org

Ready to get started?Download WordPress

Forums

WyPiekacz
Require featured image depending on category (1 post)

  1. studentrob
    Member
    Posted 1 year ago #

    In case any one is interested, here's a way to require featured images by category using Wypiekacz

    function check_my_custom_post_thumbnail( $check, $post_id, $post_data ) {
      if ( $post_id <= 0 ) {
        return false;
      }
    
      $categories = array(); //categories set by editor
      if (is_array($post_data)) {
        $categories = $post_data['post_category'];
      } elseif (is_object($post_data)) {
        $categories = $post_data->post_category;
      }
    
      $categories_requiring_image = array(4); //array containing IDs of the categories for which you want to require a featured image
    
      if (is_array($categories) && count(array_intersect($categories_requiring_image, array_values($categories)))) {
        $image = get_the_image( array(
                'post_id' => $post_id,
                'attachment' => false,
                'echo' => false,
                ) );
        return !empty($image);
      } else {
        return true;
      }
    }
    add_filter( 'wypiekacz_check_thumbnail', 'check_my_custom_post_thumbnail', 10, 3);

    http://wordpress.org/extend/plugins/wypiekacz/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.