diff --git a/bin/wp-cli.php b/bin/wp-cli.php index bfb18afb5c..7acf0f851b 100644 --- a/bin/wp-cli.php +++ b/bin/wp-cli.php @@ -760,10 +760,18 @@ private function send_bulk_errors() { */ public function status() { $this->_connect_check(); + $index_names = array(); $request_args = array( 'headers' => ep_format_request_headers() ); - $request = wp_remote_get( trailingslashit( ep_get_host( true ) ) . '_recovery/?pretty', $request_args ); + $sites = ( is_multisite() ) ? ep_get_sites() : array( 'blog_id' => get_current_blog_id() ); + foreach ( $sites as $site ) { + $index_names[] = ep_get_index_name( $site['blog_id'] ); + } + + $index_names_imploded = implode( $index_names, "," ); + + $request = wp_remote_get( trailingslashit( ep_get_host( true ) ) . $index_names_imploded . '/_recovery/?pretty', $request_args ); if ( is_wp_error( $request ) ) { WP_CLI::error( implode( "\n", $request->get_error_messages() ) ); @@ -783,18 +791,24 @@ public function status() { */ public function stats() { $this->_connect_check(); + $index_names = array(); $request_args = array( 'headers' => ep_format_request_headers() ); - $request = wp_remote_get( trailingslashit( ep_get_host( true ) ) . '_stats/', $request_args ); + $sites = ( is_multisite() ) ? ep_get_sites() : array( 'blog_id' => get_current_blog_id() ); + foreach ( $sites as $site ) { + $index_names[] = ep_get_index_name( $site['blog_id'] ); + } + + $index_names_imploded = implode( $index_names, "," ); + + $request = wp_remote_get( trailingslashit( ep_get_host( true ) ) . $index_names_imploded . '/_stats/', $request_args ); if ( is_wp_error( $request ) ) { WP_CLI::error( implode( "\n", $request->get_error_messages() ) ); } $body = json_decode( wp_remote_retrieve_body( $request ), true ); - $sites = ( is_multisite() ) ? ep_get_sites() : array( 'blog_id' => get_current_blog_id() ); - foreach ( $sites as $site ) { - $current_index = ep_get_index_name( $site['blog_id'] ); + foreach ( $index_names as $current_index ) { if (isset( $body['indices'][$current_index] ) ) { WP_CLI::log( '====== Stats for: ' . $current_index . " ======" ); diff --git a/classes/class-ep-api.php b/classes/class-ep-api.php index 30985aa727..1fae72f440 100644 --- a/classes/class-ep-api.php +++ b/classes/class-ep-api.php @@ -1530,6 +1530,30 @@ public function format_args( $args ) { } } + /** + * Sticky posts support + */ + // Check first if there's sticky posts and show them only in the front page + $sticky_posts = get_option( 'sticky_posts' ); + if( false !== $sticky_posts + && is_home() + && in_array( $args['ignore_sticky_posts'], array( 'false', 0 ) ) ) { + //let's eliminate sort so it does not mess with function_score results + $formatted_args['sort'] = array(); + $formatted_args_query = $formatted_args['query']; + $formatted_args['query'] = array(); + $formatted_args['query']['function_score']['query'] = $formatted_args_query; + $formatted_args['query']['function_score']['functions'] = array( + //add extra weight to sticky posts to show them on top + (object) array( + 'filter' => array( + 'terms' => array( '_id' => $sticky_posts ) + ), + 'weight' => 2 + ) + ); + } + /** * If not set default to post. If search and not set, default to "any". */ @@ -1928,10 +1952,8 @@ public function build_meta_query( $meta_queries ){ case 'like': if ( isset( $single_meta_query['value'] ) ) { $terms_obj = array( - 'query' => array( - 'match' => array( - $meta_key_path => $single_meta_query['value'], - ) + 'match_phrase' => array( + $meta_key_path => $single_meta_query['value'], ), ); } diff --git a/classes/class-ep-config.php b/classes/class-ep-config.php index d67c4486e1..8d5130fc47 100644 --- a/classes/class-ep-config.php +++ b/classes/class-ep-config.php @@ -119,6 +119,21 @@ public function get_index_prefix() { return apply_filters( 'ep_index_prefix', $prefix ); } + /** + * Retrieve bulk index settings + * + * @return Int The number of posts per cycle to index. Default 350. + */ + public function get_bulk_settings() { + if( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { + $bulk_settings = get_site_option( 'ep_bulk_setting', 350 ); + } else { + $bulk_settings = get_option( 'ep_bulk_setting', 350 ); + } + + return $bulk_settings; + } + /** * Retrieve the EPIO subscription credentials. * @@ -288,6 +303,10 @@ function ep_get_index_prefix() { return EP_Config::factory()->get_index_prefix(); } +function ep_get_bulk_settings() { + return EP_Config::factory()->get_bulk_settings(); +} + function ep_get_epio_credentials() { return EP_Config::factory()->get_epio_credentials(); } diff --git a/classes/class-ep-dashboard.php b/classes/class-ep-dashboard.php index 31f84ba0e6..ae65ec90c4 100644 --- a/classes/class-ep-dashboard.php +++ b/classes/class-ep-dashboard.php @@ -303,6 +303,16 @@ public function maybe_notice( $force = false ) { $notice = 'need-setup'; } + //Autosuggest defaults notice + $autosuggest = ep_get_registered_feature( 'autosuggest' ); + $autosuggest_settings = $autosuggest->get_settings(); + + if ( $autosuggest->is_active() + && isset( $autosuggest_settings['defaults_enabled'] ) + && (bool) $autosuggest_settings['defaults_enabled'] ) { + $notice = 'using-autosuggest-defaults'; + } + $notice = apply_filters( 'ep_admin_notice_type', $notice ); switch ( $notice ) { @@ -405,7 +415,7 @@ public function maybe_notice( $force = false ) { ?>
-

run a sync for it to work.', 'elasticpress' ), esc_html( $feature->title ), esc_url( $url ) ); ?>

+

run a sync for it to work.', 'elasticpress' ), esc_html( is_object( $feature ) ? $feature->title : '' ), esc_url( $url ) ); ?>

-

title ) ); ?>

+

title : '' ) ); ?>

-

-
+

+ +
+

+
+ 'integer', 'sanitize_callback' => 'absint' ) ); } } diff --git a/classes/class-ep-sync-manager.php b/classes/class-ep-sync-manager.php index 49f6fd1aaf..0633b90b14 100644 --- a/classes/class-ep-sync-manager.php +++ b/classes/class-ep-sync-manager.php @@ -265,7 +265,7 @@ public function sync_post( $post_id, $blocking = true ) { $post_args = ep_prepare_post( $post_id ); - if ( apply_filters( 'ep_post_sync_kill', false, $post_args, $post_id ) || ! $this->is_site_indexable() ) { + if ( apply_filters( 'ep_post_sync_kill', false, $post_args, $post_id ) ) { return false; } @@ -274,37 +274,6 @@ public function sync_post( $post_id, $blocking = true ) { return $response; } - /** - * Check to see if current site is indexable (public). - * - * @return bool - */ - protected function is_site_indexable() { - - if ( ! is_multisite() ) { - return true; - } - - $blog_id = get_current_blog_id(); - - $args = array( - 'fields' => 'ids', - 'public' => 1, - 'archived' => 0, - 'spam' => 0, - 'deleted' => 0, - 'update_site_cache' => false, - ); - - - if ( function_exists( 'get_sites' ) ) { - $sites = get_sites( $args ); - } else { - $sites = wp_list_pluck( wp_get_sites( $args ), 'blog_id' ); - } - - return in_array( $blog_id, $sites, true ); - } } $ep_sync_manager = EP_Sync_Manager::factory(); diff --git a/elasticpress.php b/elasticpress.php index 1b4f58714d..2ff4650d4d 100644 --- a/elasticpress.php +++ b/elasticpress.php @@ -3,7 +3,7 @@ /** * Plugin Name: ElasticPress * Description: A fast and flexible search and query engine for WordPress. - * Version: 2.7.0 + * Version: 2.8.0 * Author: Taylor Lovett, Matt Gross, Aaron Holbrook, 10up * Author URI: http://10up.com * License: GPLv2 or later @@ -22,7 +22,7 @@ define( 'EP_URL', plugin_dir_url( __FILE__ ) ); define( 'EP_PATH', plugin_dir_path( __FILE__ ) ); -define( 'EP_VERSION', '2.7.0' ); +define( 'EP_VERSION', '2.8.0' ); /** * We compare the current ES version to this compatibility version number. Compatibility is true when: diff --git a/features/autosuggest/assets/js/autosuggest.min.js b/features/autosuggest/assets/js/autosuggest.min.js index 508ae6207a..fec4b0904b 100644 --- a/features/autosuggest/assets/js/autosuggest.min.js +++ b/features/autosuggest/assets/js/autosuggest.min.js @@ -1 +1 @@ -!function(u){"use strict";if(epas.endpointUrl&&""!==epas.endpointUrl){var e=u('.ep-autosuggest, input[type="search"], .search-field'),n=u('
');e.each(function(e,t){var s=u('
'),o=u(t);o.attr("autocomplete","off"),s.insertAfter(o);var a=o.siblings("label");o.closest("form").find(".ep-autosuggest-container").append(a).append(o),n.clone().insertAfter(o),o.trigger("elasticpress.input.moved")}),n.css({top:e.outerHeight()-1,"background-color":e.css("background-color")}),u(e).each(function(e,t){u(t).on("keyup keydown keypress",function(e){38!==e.keyCode&&40!==e.keyCode||e.preventDefault(),27===e.keyCode&&p()})}),e.each(function(e,t){var s,o,a,r=u(t);r.on("keyup",(s=function(e){if(38!==e.keyCode&&40!==e.keyCode&&13!==e.keyCode&&27!==e.keyCode){var t=r.val(),s=epas.postType,o=epas.postStatus,a=epas.searchFields;2<=t.length?l(i(t,s,o,a)).done(function(e){if(0'+n+"").appendTo(o)}u(".autosuggest-item").on("click",function(e){r(a,e.target)}),a.off("keydown"),a.on("keydown",function(e){if(38===e.keyCode||40===e.keyCode||13===e.keyCode){var t,s=a.closest(".ep-autosuggest-container").find(".autosuggest-list li"),o=s.filter(".selected");switch(e.keyCode){case 38:t=o.prev();break;case 40:s.hasClass("selected")?t=o.next():(s.first().addClass("selected"),t=s.first());break;case 13:return s.hasClass("selected")?(r(a,o.children("span").get(0)),!1):void 0}return t.is("li")?(o.removeClass("selected"),t.addClass("selected")):s.removeClass("selected"),38!==e.keyCode&&void 0}})}function p(){u(".autosuggest-list").empty(),u(".ep-autosuggest").hide()}}(jQuery); \ No newline at end of file +!function(u){"use strict";if(epas.endpointUrl&&""!==epas.endpointUrl){var e=u('.ep-autosuggest, input[type="search"], .search-field'),n=u('
');e.each(function(e,t){var s=u('
'),o=u(t);o.attr("autocomplete","off"),s.insertAfter(o);var a=o.siblings("label");o.closest("form").find(".ep-autosuggest-container").append(a).append(o),n.clone().insertAfter(o),o.trigger("elasticpress.input.moved")}),n.css({top:e.outerHeight()-1,"background-color":e.css("background-color")}),u(e).each(function(e,t){u(t).on("keyup keydown keypress",function(e){38!==e.keyCode&&40!==e.keyCode||e.preventDefault(),27===e.keyCode&&p()})}),e.each(function(e,t){var s,o,a,r=u(t);r.on("keyup",(s=function(e){if(38!==e.keyCode&&40!==e.keyCode&&13!==e.keyCode&&27!==e.keyCode){var t=r.val(),s=epas.postType,o=epas.postStatus,a=epas.searchFields;2<=t.length?l(i(t,s,o,a)).done(function(e){if(0'+n+"").appendTo(o)}u(".autosuggest-item").on("click",function(e){r(a,e.target)}),a.off("keydown"),a.on("keydown",function(e){if(38===e.keyCode||40===e.keyCode||13===e.keyCode){var t,s=a.closest(".ep-autosuggest-container").find(".autosuggest-list li"),o=s.filter(".selected");switch(e.keyCode){case 38:t=o.prev();break;case 40:t=s.hasClass("selected")?o.next():(s.first().addClass("selected"),s.first());break;case 13:return s.hasClass("selected")?(r(a,o.children("span").get(0)),!1):void 0}return t.is("li")?(o.removeClass("selected"),t.addClass("selected")):s.removeClass("selected"),38!==e.keyCode&&void 0}})}function p(){u(".autosuggest-list").empty(),u(".ep-autosuggest").hide()}}(jQuery); \ No newline at end of file diff --git a/features/autosuggest/assets/js/src/autosuggest.js b/features/autosuggest/assets/js/src/autosuggest.js index bef6168e73..8ffd697a30 100644 --- a/features/autosuggest/assets/js/src/autosuggest.js +++ b/features/autosuggest/assets/js/src/autosuggest.js @@ -39,8 +39,8 @@ /** * Respond to an item selection based on the predefined behavior. - * If epas.action is set to "navigate", redirects the browser to the URL of the selected item - * If epas.action is set to any other value (default "search"), fill in the value and perform the search + * If epas.action is set to "navigate" (the default), redirects the browser to the URL of the selected item + * If epas.action is set to any other value (such as "search"), fill in the value and perform the search * * @param $localInput * @param element @@ -90,7 +90,7 @@ } if ( postStatus === '' ) { - postType = 'publish'; + postStatus = 'publish'; } var query = { diff --git a/features/autosuggest/autosuggest.php b/features/autosuggest/autosuggest.php index ad7254f289..cfac56c573 100644 --- a/features/autosuggest/autosuggest.php +++ b/features/autosuggest/autosuggest.php @@ -34,7 +34,7 @@ function ep_autosuggest_setup() { } /** - * Display decaying settings on dashboard. + * Display autosuggest settings on dashboard. * * @param EP_Feature $feature Feature object. * @since 2.4 @@ -49,6 +49,16 @@ function ep_autosugguest_settings( $feature ) { $settings = wp_parse_args( $settings, $feature->default_settings ); + ?> +
+
+
+
+ +
+
+ get_settings(); + if ( defined( 'EP_AUTOSUGGEST_ENDPOINT' ) && EP_AUTOSUGGEST_ENDPOINT ) { $endpoint_url = EP_AUTOSUGGEST_ENDPOINT; } else { if ( preg_match( '#elasticpress\.io#i', $host ) ) { $endpoint_url = $host . '/' . ep_get_index_name() . '/post/_search'; } else { - $settings = $feature->get_settings(); if ( ! $settings ) { $settings = array(); @@ -193,10 +204,22 @@ function ep_autosuggest_enqueue_scripts() { * postType: which post types to use for suggestions * action: the action to take when selecting an item. Possible values are "search" and "navigate". */ + if ( ! isset( $settings['defaults_enabled'] ) || (bool) $settings['defaults_enabled'] ) { + foreach( ep_get_indexable_post_types() as $post_type ) { + $post_types[] = $post_type; + } + foreach( ep_get_indexable_post_status() as $post_status ) { + $post_statuses[] = $post_status; + } + } else { + $post_statuses = array( 'publish' ); + $post_types = array( 'post', 'page' ); + } + wp_localize_script( 'elasticpress-autosuggest', 'epas', apply_filters( 'ep_autosuggest_options', array( 'endpointUrl' => esc_url( untrailingslashit( $endpoint_url ) ), - 'postType' => apply_filters( 'ep_term_suggest_post_type', array( 'post', 'page' ) ), - 'postStatus' => apply_filters( 'ep_term_suggest_post_status', 'publish' ), + 'postType' => apply_filters( 'ep_term_suggest_post_type', $post_types ), + 'postStatus' => apply_filters( 'ep_term_suggest_post_status', $post_statuses ), 'searchFields' => apply_filters( 'ep_term_suggest_search_fields', array( 'post_title.suggest', 'term_suggest', @@ -215,7 +238,7 @@ function ep_autosuggest_enqueue_scripts() { function ep_autosuggest_requirements_status( $status ) { $host = ep_get_host(); - $status->code = 1; + $status->code = 0; $status->message = array(); @@ -223,6 +246,7 @@ function ep_autosuggest_requirements_status( $status ) { if ( ! preg_match( '#elasticpress\.io#i', $host ) ) { $status->message[] = wp_kses_post( __( "You aren't using ElasticPress.io so we can't be sure your host is properly secured. Autosuggest requires a publicly accessible endpoint, which can expose private content and allow data modification if improperly configured.", 'elasticpress' ) ); + $status->code = 1; } return $status; @@ -251,6 +275,7 @@ function ep_autosuggest_setup_settings() { 'requires_install_reindex' => true, 'requirements_status_cb' => 'ep_autosuggest_requirements_status', 'default_settings' => array( + 'defaults_enabled' => 1, 'endpoint_url' => '', ), ) ); diff --git a/features/documents/documents.php b/features/documents/documents.php index 9d881524e8..7c3c3fe3ca 100644 --- a/features/documents/documents.php +++ b/features/documents/documents.php @@ -207,6 +207,7 @@ function ep_documents_requirements_status( $status ) { $status->message[] = __( 'The Ingest Attachment plugin for Elasticsearch is not installed. To get the most out of ElasticPress, without the hassle of Elasticsearch management, check out ElasticPress.io hosting.', 'elasticpress' ); } else { $status->message[] = __( "This feature modifies the default user experience for your visitors by adding popular document file types to search results. All supported documents uploaded to your media library will appear in search results.", 'elasticpress' ); + $status->code = 0; } return $status; diff --git a/features/facets/class-ep-facet-widget.php b/features/facets/class-ep-facet-widget.php index 2b6164c9ba..543a6cddc4 100644 --- a/features/facets/class-ep-facet-widget.php +++ b/features/facets/class-ep-facet-widget.php @@ -110,7 +110,9 @@ public function widget( $args, $instance ) {
$search_threshold ) : ?> - +
@@ -229,6 +231,9 @@ public function widget( $args, $instance ) {
false ) ); // We don't want to deal with nav menus - unset( $all_post_types['nav_menu_item'] ); + if ( $pc_post_types['nav_menu_item'] ) { + unset( $pc_post_types['nav_menu_item'] ); + } - return array_unique( array_merge( $post_types, $all_post_types ) ); + // Merge non public post types with any pre-filtered post_type + return array_merge( $post_types, $pc_post_types); } /** * Integrate EP into proper queries - * + * * @param WP_Query $query * @since 2.1 */ @@ -89,11 +93,18 @@ function ep_pc_integrate( $query ) { $query->set( 'ep_integrate', true ); } } + + /** + * Remove articles weighting by date in admin. + * + * @since 2.4 + */ + remove_filter( 'ep_formatted_args', 'ep_weight_recent', 10 ); } /** * Output feature box summary - * + * * @since 2.1 */ function ep_pc_feature_box_summary() { @@ -104,7 +115,7 @@ function ep_pc_feature_box_summary() { /** * Output feature box long - * + * * @since 2.1 */ function ep_pc_feature_box_long() { diff --git a/features/woocommerce/woocommerce.php b/features/woocommerce/woocommerce.php index 9cee033e68..8ceddca5c3 100644 --- a/features/woocommerce/woocommerce.php +++ b/features/woocommerce/woocommerce.php @@ -459,12 +459,19 @@ function ep_wc_translate_args( $query ) { // Remove author_name from this search. $search_fields = ep_wc_remove_author($search_fields); - // Make sure we search skus on the front end - $search_fields['meta'] = array( '_sku' ); - - // Search by proper taxonomies on the front end - $search_fields['taxonomies'] = array( 'category', 'post_tag', 'product_tag', 'product_cat' ); + // Make sure we search skus on the front end and do not override meta search fields + if( ! empty( $search_fields['meta'] ) ) { + $search_fields['meta'] = array_merge( $search_fields['meta'], array( '_sku' ) ); + } else { + $search_fields['meta'] = array( '_sku' ); + } + // Search by proper taxonomies on the front end and do not override taxonomy search fields + if( ! empty( $search_fields['taxonomies'] ) ) { + $search_fields['meta'] = array_merge( $search_fields['meta'], array( 'category', 'post_tag', 'product_tag', 'product_cat' ) ); + } else { + $search_fields['taxonomies'] = array( 'category', 'post_tag', 'product_tag', 'product_cat' ); + } $query->set( 'search_fields', $search_fields ); } } else { @@ -489,6 +496,14 @@ function ep_wc_translate_args( $query ) { } } + /** + * Set orderby and order for price when GET param not set + */ + if( isset( $query->query_vars['orderby'], $query->query_vars['order'] ) && 'price' === $query->query_vars['orderby'] && $query->is_main_query() ) { + $query->set( 'order', $query->query_vars['order'] ); + $query->set( 'orderby', ep_wc_get_orderby_meta_mapping( '_price' ) ); + } + /** * Set orderby from GET param * Also make sure the orderby param affects only the main query diff --git a/includes/settings-page.php b/includes/settings-page.php index 0886e665c4..ba4b995cd5 100644 --- a/includes/settings-page.php +++ b/includes/settings-page.php @@ -18,6 +18,8 @@ } else { $index_meta = get_option( 'ep_index_meta', false ); } + +$ep_host = ep_get_host(); ?> @@ -34,10 +36,11 @@ - + + - disabled placeholder="http://" type="text" value="" name="ep_host" id="ep_host"> + disabled placeholder="http://" type="text" value="" name="ep_host" id="ep_host"> @@ -46,6 +49,17 @@ + + + + + + + + + + + - disabled type="text" value="" name="ep_prefix" id="ep_prefix"> + disabled type="text" value="" name="ep_prefix" id="ep_prefix"> @@ -84,7 +98,18 @@ - + + + + + + + + diff --git a/readme.txt b/readme.txt index e698462f84..6d91c42e42 100644 --- a/readme.txt +++ b/readme.txt @@ -40,6 +40,26 @@ Please refer to [Github](https://github.com/10up/ElasticPress) for detailed usag == Changelog == += 2.8.0 = + +ElasticPress 2.8 provides some new enhancements and bug fixes. + +* Sticky posts support. +* Meta LIKE query adjustment. +* Autosuggest bugfix. +* Autosuggest to abide by plugin settings. +* WooCommerce searches with custom fields. +* Adjustment to `wp elasticpress status` +* Add Elasticsearch version in settings. (Props [turtlepod](https://github.com/turtlepod)) +* Allow user to set number of posts during bulk indexing cycle. +* Facet query string customization (Props [ray-lee](https://github.com/ray-lee)) +* Removal of logic that determines if blog is public / indexable. (Resolves sync issue.) +* Fix for auto activating sync notices. (Props [petenelson](https://github.com/petenelson)) +* Removal of date weighting for protected content admin queries. +* Protected content: filtering of filtered post types. +* Implemented --post-ids CLI option to index only specific posts. (Props [dotancohen](https://github.com/dotancohen)) + + = 2.7.0 (Requires re-index) = ElasticPress 2.7 provides some new enhancements and bug fixes. diff --git a/tests/test-single-site.php b/tests/test-single-site.php index 38a47a9887..1c8f72d2e4 100644 --- a/tests/test-single-site.php +++ b/tests/test-single-site.php @@ -2327,6 +2327,7 @@ public function testMetaQueryLike() { $query = new WP_Query( $args ); + $this->assertTrue( isset( $query->posts[0]->elasticsearch ) ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); } @@ -2560,33 +2561,6 @@ public function testCachedResultIsNotInCache() { } - /** - * Test if $post object values exist after receiving odd values from the 'ep_search_post_return_args' filter. - * - * @link https://github.com/10up/ElasticPress/issues/306 - * @group single-site - */ - public function testPostReturnArgs() { - add_filter( 'ep_search_post_return_args', array( $this, 'ep_search_post_return_args_filter' ) ); - ep_create_and_sync_post( array( 'post_content' => 'findme' ) ); - ep_refresh_index(); - $args = array( - 's' => 'findme' - ); - $query = new WP_Query( $args ); - remove_filter( 'ep_search_post_return_args', array( $this, 'ep_search_post_return_args_filter' ) ); - } - - /** - * Adds fake_item to post_return_args. - * @param array $args - * @return string - */ - public function ep_search_post_return_args_filter( $args ) { - $args[] = 'fake_item'; - return $args; - } - /** * Helper method for mocking indexable post statuses * @@ -3519,4 +3493,47 @@ public function testCustomTaxonomyPublic() { $this->assertTrue( isset( $query->posts[0]->elasticsearch ) ); } + /** + * If a post is sticky and we are on the home page, it should return at the top. + * + * @group single-site + */ + public function testStickyPostsIncludedOnHome() { + ep_create_and_sync_post( array( 'post_title' => 'Normal post 1' ) ); + $sticky_id = ep_create_and_sync_post( array( 'post_title' => 'Sticky post' ) ); + stick_post( $sticky_id ); + ep_create_and_sync_post( array( 'post_title' => 'Normal post 2' ) ); + + ep_refresh_index(); + + $this->go_to( '/' ); + + $q = $GLOBALS['wp_query']; + + $this->assertEquals( 'Sticky post', $q->posts[0]->post_title ); + } + + /** + * If a post is not sticky and we are not on the home page, it should not return at the top. + * + * @group single-site + */ + public function testStickyPostsExcludedOnNotHome() { + ep_create_and_sync_post( array( 'post_title' => 'Normal post 1' ) ); + $sticky_id = ep_create_and_sync_post( array( 'post_title' => 'Sticky post' ) ); + stick_post( $sticky_id ); + ep_create_and_sync_post( array( 'post_title' => 'Normal post 2' ) ); + + ep_refresh_index(); + + + $args = array( + 's' => '' + ); + + $query = new WP_Query( $args ); + + $this->assertNotEquals( 'Sticky post', $query->posts[0]->post_title ); + } + }