• 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_ajax_download_search() – Retrieve a states drop down

You appear to be a bot. Output may be restricted

Description

Retrieve a states drop down

Usage

$void = edd_ajax_download_search();

Parameters

Returns

void

Source

File name: easy-digital-downloads/includes/ajax-functions.php
Lines:

1 to 98 of 98
function edd_ajax_download_search() {
  global $wpdb;

  $search   = esc_sql( sanitize_text_field( $_GET['s'] ) );
  $excludes = ( isset( $_GET['current_id'] ) ? (array) $_GET['current_id'] : array() );

  $no_bundles = isset( $_GET['no_bundles'] ) ? filter_var( $_GET['no_bundles'], FILTER_VALIDATE_BOOLEAN ) : false;
  if( true === $no_bundles ) {
    $bundles  = $wpdb->get_results( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_edd_product_type' AND meta_value = 'bundle';", ARRAY_A );
    $bundles  = wp_list_pluck( $bundles, 'post_id' );
    $excludes = array_merge( $excludes, $bundles );
  }

  $variations = isset( $_GET['variations'] ) ? filter_var( $_GET['variations'], FILTER_VALIDATE_BOOLEAN ) : false;

  $excludes = array_unique( array_map( 'absint', $excludes ) );
  $exclude  = implode( ",", $excludes );

  $results = array();

  // Setup the SELECT statement
  $select = "SELECT ID,post_title FROM $wpdb->posts ";

  // Setup the WHERE clause
  $where = "WHERE `post_type` = 'download' and `post_title` LIKE '%s' ";

  // If we have items to exclude, exclude them
  if( ! empty( $exclude ) ) {
    $where .= "AND `ID` NOT IN (" . $exclude . ") ";
  }

  if ( ! current_user_can( 'edit_products' ) ) {
    $status = apply_filters( 'edd_product_dropdown_status_nopriv', array( 'publish' ) );
  } else {
    $status = apply_filters( 'edd_product_dropdown_status', array( 'publish', 'draft', 'private', 'future' ) );
  }

  if ( is_array( $status ) && ! empty( $status ) ) {

    $status     = array_map( 'sanitize_text_field', $status );
    $status_in  = "'" . join( "', '", $status ) . "'";
    $where     .= "AND `post_status` IN ({$status_in}) ";

  } else {

    $where .= "AND `post_status` = `publish` ";

  }

  // Limit the result sets
  $limit = "LIMIT 50";

  $sql = $select . $where . $limit;

  $prepared_statement = $wpdb->prepare( $sql, '%' . $search . '%' );

  $items = $wpdb->get_results( $prepared_statement );

  if( $items ) {

    foreach( $items as $item ) {

      $results[] = array(
        'id'   => $item->ID,
        'name' => $item->post_title
      );

      if ( $variations && edd_has_variable_prices( $item->ID ) ) {
        $prices = edd_get_variable_prices( $item->ID );

        foreach ( $prices as $key => $value ) {
          $name   = ! empty( $value['name'] )   ? $value['name']   : '';
          $amount = ! empty( $value['amount'] ) ? $value['amount'] : '';
          $index  = ! empty( $value['index'] )  ? $value['index']  : $key;

          if ( $name && $index ) {
            $results[] = array(
              'id'   => $item->ID . '_' . $key,
              'name' => esc_html( $item->post_title . ': ' . $name ),
            );
          }
        }
      }
    }

  } else {

    $results[] = array(
      'id'   => 0,
      'name' => __( 'No results found', 'easy-digital-downloads' )
    );

  }

  echo json_encode( $results );

  edd_die();
}
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 26th November 2019

Primary Sidebar

Information

Function name: edd_ajax_download_search
Plugin ref: Easy Digital Downloads
Version: 2.10.1
Sourcefile: includes/ajax-functions.php
File ref: includes/ajax-functions.php
Deprecated?: No
API Letters: A,D,E,S

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.7
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