AnsPress_Admin::join_by_author_name( array $pieces, object $query )

Description #

Join users table in post table for searching posts by on user_login.

Parameters #

  • $pieces
    array (Required) Wp_Query mysql clauses.
  • $query
    object (Required) Parent class.

Changelog #

VersionDescription
2.4Introduced.

Source #

File: admin/anspress-admin.php

	public static function join_by_author_name( $pieces, $query ) {
		if ( isset( $query->query_vars['ap_author_name'] ) && is_array( $query->query_vars['ap_author_name'] ) && count( $query->query_vars['ap_author_name'] ) > 0 ) {
			global $wpdb;
			$authors        = $query->query_vars['ap_author_name'];
			$authors        = implode( "','", array_map( 'sanitize_title_for_query', array_unique( (array) $authors ) ) );
			$authors        = "'" . rtrim( $authors, ",'" ) . "'";
			$pieces['join'] = " JOIN $wpdb->users users ON users.ID = $wpdb->posts.post_author AND users.user_login IN ($authors)"; // @codingStandardsIgnoreLine.
		}

		return $pieces;
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment