• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / EDD_API_V2::get_products() – Process Get Products API Request

You appear to be a bot. Output may be restricted

Description

Process Get Products API Request

Usage

$array = EDD_API_V2::get_products( $args );

Parameters

$args
( array ) optional – Query arguments

Returns

array $customers Multidimensional array of the products

Source

File name: easy-digital-downloads/includes/api/class-edd-api-v2.php


Lines:

1 to 100 of 143
  public function get_products( $args = array() ) {

    $products = array();
    $error    = array();

    if ( empty( $args['product'] ) ) {

      $products['products'] = array();

      $query_args = array(
        'post_type'        => 'download',
        'posts_per_page'   => $this->per_page(),
        'suppress_filters' => true,
        'paged'            => $this->get_paged(),
        'order'            => $args['order'],
        'orderby'          => $args['orderby'],
      );

      if( ! empty( $args['s'] ) ) {
        $query_args['s'] = sanitize_text_field( $args['s'] );
      }

      switch ( $query_args['orderby'] ) {
        case 'price':
          $query_args['meta_key'] = 'edd_price';
          $query_args['orderby']  = 'meta_value_num';
          break;

        case 'sales':
          if ( user_can( $this->user_id, 'view_shop_sensitive_data' ) || current_user_can( 'view_shop_sensitive_data' ) || $this->override ) {
            $query_args['meta_key'] = '_edd_download_sales';
            $query_args['orderby']  = 'meta_value_num';
          }
          break;

        case 'earnings':
          if ( user_can( $this->user_id, 'view_shop_sensitive_data' ) || current_user_can( 'view_shop_sensitive_data' ) || $this->override ) {
            $query_args['meta_key'] = '_edd_download_earnings';
            $query_args['orderby']  = 'meta_value_num';
          }
          break;

      }

      if( ! empty( $args['category'] ) ) {
        if ( is_string( $args[ 'categrory' ] ) ) {
          $args['category'] = explode( ',', $args['category'] );
        }

        if ( is_numeric( $args['category'] ) ) {
          $query_args['tax_query'] = array(
            array(
              'taxonomy' => 'download_category',
              'field'    => 'ID',
              'terms'    => (int) $args['category']
            ),
          );
        } else if ( is_array( $args['category'] ) ) {

          foreach ( $args['category'] as $category ) {


            $field = is_numeric( $category ) ? 'ID': 'slug';

            $query_args['tax_query'][] = array(
              'taxonomy' => 'download_category',
              'field'    => $field,
              'terms'    => $category,
            );

          }

        } else {
          $query_args['download_category'] = $args['category'];
        }
      }

      if( ! empty( $args['tag'] ) ) {
        if ( strpos( $args['tag'], ',' ) ) {
          $args['tag'] = explode( ',', $args['tag'] );
        }

        if ( is_numeric( $args['tag'] ) ) {
          $query_args['tax_query'] = array(
            array(
              'taxonomy' => 'download_tag',
              'field'    => 'ID',
              'terms'    => (int) $args['tag']
            ),
          );
        } else if ( is_array( $args['tag'] ) ) {

          foreach ( $args['tag'] as $tag ) {


            $field = is_numeric( $tag ) ? 'ID': 'slug';

            $query_args['tax_query'][] = array(
              'taxonomy' => 'download_tag',
              'field'    => $field,
[1] [2] Next »

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 23rd February 2021

Primary Sidebar

Information

Function name: EDD_API_V2::get_products
Class ref: EDD_API_V2
Plugin ref: Easy Digital Downloads
Version: 2.9.26
Sourcefile: includes/api/class-edd-api-v2.php
File ref: includes/api/class-edd-api-v2.php
Deprecated?: No
API Letters: A,E,G,P,V

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.6.2
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites