def blog__get_posts(
      order: nil,
      language: nil,
      category_permalink: nil,
      category_permalink_AND: false,
      category_id: nil,
      category_id_AND: false,
      tag_permalink: nil,
      tag_permalink_AND: false,
      tag_id: nil,
      tag_id_AND: false,
      search: nil,
      page: nil,
      per_page: nil
    )
      posts = LatoBlog::Post.published.joins(:post_parent).where('lato_blog_post_parents.publication_datetime <= ?', DateTime.now)

      # apply filters
      order = order && order == 'ASC' ? 'ASC' : 'DESC'
      posts = _posts_filter_by_order(posts, order)
      posts = _posts_filter_by_language(posts, language)
      if category_permalink || category_id
        posts = posts.joins(:categories)
        posts = _posts_filter_by_category_permalink(posts, category_permalink, category_permalink_AND)
        posts = _posts_filter_category_id(posts, category_id, category_id_AND)
      end
      if tag_permalink || tag_id
        posts = posts.joins(:tags)
        posts = _posts_filter_by_tag_permalink(posts, tag_permalink, tag_permalink_AND)
        posts = _posts_filter_tag_id(posts, tag_id, tag_id_AND)
      end
      posts = _posts_filter_search(posts, search)

      # take posts uniqueness
      posts = posts.uniq(&:id)

      # save total posts
      total = posts.length

      # manage pagination
      page = page&.to_i || 1
      per_page = per_page&.to_i || 20
      posts = core__paginate_array(posts, per_page, page)

      # return result
      {
        posts: posts && !posts.empty? ? posts.map(&:serialize) : [],
        page: page,
        per_page: per_page,
        order: order,
        total: total
      }
    end
def blog__get_posts(
      order: nil,
      language: nil,
      category_permalink: nil,
      category_permalink_AND: false,
      category_id: nil,
      category_id_AND: false,
      tag_permalink: nil,
      tag_permalink_AND: false,
      tag_id: nil,
      tag_id_AND: false,
      search: nil,
      page: nil,
      per_page: nil
    )
      posts = LatoBlog::Post.published.joins(:post_parent).where('lato_blog_post_parents.publication_datetime <= ?', DateTime.now)

      # apply filters
      order = order && order == 'ASC' ? 'ASC' : 'DESC'
      posts = _posts_filter_by_order(posts, order)
      posts = _posts_filter_by_language(posts, language)
      if category_permalink || category_id
        posts = posts.joins(:categories)
        posts = _posts_filter_by_category_permalink(posts, category_permalink, category_permalink_AND)
        posts = _posts_filter_category_id(posts, category_id, category_id_AND)
      end
      if tag_permalink || tag_id
        posts = posts.joins(:tags)
        posts = _posts_filter_by_tag_permalink(posts, tag_permalink, tag_permalink_AND)
        posts = _posts_filter_tag_id(posts, tag_id, tag_id_AND)
      end
      posts = _posts_filter_search(posts, search)

      # take posts uniqueness
      posts = posts.uniq(&:id)

      # save total posts
      total = posts.length

      # manage pagination
      page = page&.to_i || 1
      per_page = per_page&.to_i || 20
      posts = core__paginate_array(posts, per_page, page)

      # return result
      {
        posts: posts && !posts.empty? ? posts.map(&:serialize) : [],
        page: page,
        per_page: per_page,
        order: order,
        total: total
      }
    end
This function returns an object with the list of posts with some filters.