Skip to content

Commit

Permalink
Changes to sticky posts (#1245)
Browse files Browse the repository at this point in the history
* Changes to sticky posts.

* Removing redundant code.
  • Loading branch information
Allan Collins authored Feb 13, 2019
1 parent 70df121 commit e1047a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions classes/class-ep-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1539,12 +1539,24 @@ 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' );
$sticky_posts = ( is_array( $sticky_posts ) && empty( $sticky_posts ) ) ? false : $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();

$new_sort = array(
array(
'_score' => array(
'order' => 'desc',
),
)
);

$formatted_args['sort'] = array_merge( $new_sort, $formatted_args['sort'] );

$formatted_args_query = $formatted_args['query'];
$formatted_args['query'] = array();
$formatted_args['query']['function_score']['query'] = $formatted_args_query;
Expand All @@ -1554,7 +1566,7 @@ public function format_args( $args ) {
'filter' => array(
'terms' => array( '_id' => $sticky_posts )
),
'weight' => 2
'weight' => 20
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion features/autosuggest/autosuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ 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( (bool)$settings['defaults_enabled'] ) {
if ( ! isset( $settings['defaults_enabled'] ) || (bool) $settings['defaults_enabled'] ) {
foreach( ep_get_indexable_post_types() as $post_type ) {
$post_types[] = $post_type;
}
Expand Down

0 comments on commit e1047a5

Please sign in to comment.