//Stick featured ads to the top on category and search pages class StickyAds { public function __construct() { add_filter('posts_orderby', array($this, '_hookPostsOrderBy'), 11, 2); } public function _hookPostsOrderBy($orderBy, $query) { global $wpdb; if ( is_tax( array( APP_TAX_CAT, APP_TAX_TAG ) ) || is_search() && !$query->query_vars['ignore_sticky_posts']) { $stickyPosts = get_option('sticky_posts'); if (is_array($stickyPosts) && !empty($stickyPosts)) { $sticky = '(' . $wpdb->posts . '.ID IN (' . implode(',', $stickyPosts) . ')) DESC'; $orderBy= empty($orderBy) ? $sticky : $sticky . ',' . $orderBy; add_filter('pre_option_sticky_posts', array($this, '_hookOptionStickyPosts') ); } } return $orderBy; } public function _hookOptionStickyPosts($option) { remove_filter('pre_option_sticky_posts', array($this, '_hookOptionStickyPosts') ); return array(); } } $stickyads = new StickyAds(); // End sticky ads
There are currently 1 users browsing this thread. (0 members and 1 guests)