• 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 downloads drop down

You appear to be a bot. Output may be restricted

Description

Retrieve a downloads drop down

Usage

$void = edd_ajax_download_search();

Parameters

Returns

void

Source

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

1 to 100 of 137
function edd_ajax_download_search() {

  // We store the last search in a transient for 30 seconds. This _might_
  // result in a race condition if 2 users are looking at the exact same time,
  // but we'll worry about that later if that situation ever happens.
  $args   = get_transient( 'edd_download_search' );

  // Parse args
  $search = wp_parse_args( (array) $args, array(
    'text'    => '',
    'results' => array()
  ) );

  // Get the search string
  $new_search = isset( $_GET['s'] )
    ? sanitize_text_field( $_GET['s'] )
    : '';

  // Bail early if the search text has not changed
  if ( $search['text'] === $new_search ) {
    echo json_encode( $search['results'] );
    edd_die();
  }

  // Set the local static search variable
  $search['text'] = $new_search;

  // Are we excluding the current ID?
  $excludes = isset( $_GET['current_id'] )
    ? array_unique( array_map( 'absint', (array) $_GET['current_id'] ) )
    : array();

  // Are we excluding bundles?
  $no_bundles = isset( $_GET['no_bundles'] )
    ? filter_var( $_GET['no_bundles'], FILTER_VALIDATE_BOOLEAN )
    : false;

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

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

  // Are we including all statuses, or only public ones?
  $status = ! current_user_can( 'edit_products' )
    ? apply_filters( 'edd_product_dropdown_status_nopriv', array( 'publish' ) )
    : apply_filters( 'edd_product_dropdown_status',        array( 'publish', 'draft', 'private', 'future' ) );

  // Default query arguments
  $args = array(
    'orderby'          => 'title',
    'order'            => 'ASC',
    'post_type'        => 'download',
    'posts_per_page'   => 50,
    'post_status'      => implode( ',', $status ), // String
    'post__not_in'     => $excludes,               // Array
    'edd_search'       => $new_search,              // String
    'suppress_filters' => false,
  );

  // Maybe exclude bundles.
  if ( true === $no_bundles ) {
    $args['meta_query'] = array(
      'relation' => 'OR',
      array(
        'key'     => '_edd_product_type',
        'value'   => 'bundle',
        'compare' => '!=',
      ),
      array(
        'key'     => '_edd_product_type',
        'value'   => 'bundle',
        'compare' => 'NOT EXISTS',
      ),
    );
  }

  add_filter( 'posts_where', 'edd_ajax_filter_download_where', 10, 2 );
  // Get downloads
  $items = get_posts( $args );
  remove_filter( 'posts_where', 'edd_ajax_filter_download_where', 10, 2 );

  // Pluck title & ID
  if ( ! empty( $items ) ) {
    $items = wp_list_pluck( $items, 'post_title', 'ID' );

    // Loop through all items...
    foreach ( $items as $post_id => $title ) {
      $product_title = $title;

      // Look for variable pricing
      $prices = edd_get_variable_prices( $post_id );

      if ( ! empty( $prices ) && ( false === $variations|| ! $variations_only ) ) {
        $title .= ' (' . __( 'All Price Options', 'easy-digital-downloads' ) . ')';
      }

 
[1] [2] Next »

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 14th September 2022

Primary Sidebar

Information

Function name: edd_ajax_download_search
Plugin ref: Easy Digital Downloads
Version: 3.1.0.2
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 6.2.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-2023. All rights reserved.


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