• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / ActionScheduler_wpPostStore::get_query_actions_sql() – Returns the SQL statement to query (or count) actions.

You appear to be a bot. Output may be restricted

Description

Returns the SQL statement to query (or count) actions.

Usage

$string = ActionScheduler_wpPostStore::get_query_actions_sql( $query, $select_or_count );

Parameters

$query
( array ) required – Filtering options
$select_or_count
( string ) optional default: select – Whether the SQL should select and return the IDs or just the row count

Returns

string SQL statement. The returned SQL is already properly escaped.

Source

File name: woocommerce/packages/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php


Lines:

1 to 100 of 129
  protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) {

    if ( ! in_array( $select_or_count, array( 'select', 'count' ) ) ) {
      throw new InvalidArgumentException( __( 'Invalid schedule. Cannot save action.', 'woocommerce' ) );
    }

    $query = wp_parse_args( $query, array(
      'hook' => '',
      'args' => NULL,
      'date' => NULL,
      'date_compare' => '<=',
      'modified' => NULL,
      'modified_compare' => '<=',
      'group' => '',
      'status' => '',
      'claimed' => NULL,
      'per_page' => 5,
      'offset' => 0,
      'orderby' => 'date',
      'order' => 'ASC',
      'search' => '',
    ) );

    
/** @var wpdb $wpdb */
    global $wpdb;
    $sql  = ( 'count' === $select_or_count ) ? 'SELECT count(p.ID)' : 'SELECT p.ID ';
    $sql .= "FROM {$wpdb->posts} p";
    $sql_params = array();
    if ( empty( $query['group'] ) && 'group' === $query['orderby'] ) {
      $sql .= " LEFT JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID";
      $sql .= " LEFT JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id";
      $sql .= " LEFT JOIN {$wpdb->terms} t ON tt.term_id=t.term_id";
    } elseif ( ! empty( $query['group'] ) ) {
      $sql .= " INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID";
      $sql .= " INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id";
      $sql .= " INNER JOIN {$wpdb->terms} t ON tt.term_id=t.term_id";
      $sql .= " AND t.slug=%s";
      $sql_params[] = $query['group'];
    }
    $sql .= " WHERE post_type=%s";
    $sql_params[] = self::POST_TYPE;
    if ( $query['hook'] ) {
      $sql .= " AND p.post_title=%s";
      $sql_params[] = $query['hook'];
    }
    if ( !is_null($query['args']) ) {
      $sql .= " AND p.post_content=%s";
      $sql_params[] = json_encode($query['args']);
    }

    if ( ! empty( $query['status'] ) ) {
      $sql .= " AND p.post_status=%s";
      $sql_params[] = $this->get_post_status_by_action_status( $query['status'] );
    }

    if ( $query['date'] instanceof DateTime ) {
      $date = clone $query['date'];
      $date->setTimezone( new DateTimeZone('UTC') );
      $date_string = $date->format('Y-m-d H:i:s');
      $comparator = $this->validate_sql_comparator($query['date_compare']);
      $sql .= " AND p.post_date_gmt $comparator %s";
      $sql_params[] = $date_string;
    }

    if ( $query['modified'] instanceof DateTime ) {
      $modified = clone $query['modified'];
      $modified->setTimezone( new DateTimeZone('UTC') );
      $date_string = $modified->format('Y-m-d H:i:s');
      $comparator = $this->validate_sql_comparator($query['modified_compare']);
      $sql .= " AND p.post_modified_gmt $comparator %s";
      $sql_params[] = $date_string;
    }

    if ( $query['claimed'] === TRUE ) {
      $sql .= " AND p.post_password != ''";
    } elseif ( $query['claimed'] === FALSE ) {
      $sql .= " AND p.post_password = ''";
    } elseif ( !is_null($query['claimed']) ) {
      $sql .= " AND p.post_password = %s";
      $sql_params[] = $query['claimed'];
    }

    if ( ! empty( $query['search'] ) ) {
      $sql .= " AND (p.post_title LIKE %s OR p.post_content LIKE %s OR p.post_password LIKE %s)";
      for( $i = 0; $i < 3; $i++ ) {
        $sql_params[] = sprintf( '%%%s%%', $query['search'] );
      }
    }

    if ( 'select' === $select_or_count ) {
      switch ( $query['orderby'] ) {
        case 'hook':
          $orderby = 'p.post_title';
          break;
        case 'group':
          $orderby = 't.name';
          break;
        case 'status':
          $orderby = 'p.post_status';
[1] [2] Next »

 View on GitHub View on Trac

Published: 8th February 2020 | Last updated: 6th April 2020

Primary Sidebar

Information

Function name: ActionScheduler_wpPostStore::get_query_actions_sql
Class ref: ActionScheduler_wpPostStore
Plugin ref: WooCommerce
Version: 5.1.0
Sourcefile: packages/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php
File ref: packages/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php
Deprecated?: No
API Letters: A,G,Q,W

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.7.1
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:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


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

  • Home
  • Blog
  • Sitemap
  • Sites