Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    It is default behaviour of wp_query. You can use the below code to display sticky post on top on archive page –

    function prefix_sticky_first_order( $clauses, $query ) {
    if ( !is_admin() && $query->is_main_query() && is_category() ) {

    $sticky_posts = get_option('sticky_posts');

    if ( !empty($sticky_posts) ) {
    global $wpdb;

    $sticky_ids = implode(',', array_map('intval', $sticky_posts));

    $clauses['orderby'] = "
    FIELD({$wpdb->posts}.ID, $sticky_ids) DESC,
    {$wpdb->posts}.post_date DESC
    ";
    }
    }

    return $clauses;
    }
    add_filter( 'posts_clauses', 'prefix_sticky_first_order', 10, 2 );
    Thread Starter Michael Rieder

    (@teamtacho)

    Dear Amit

    Thank you very much. Works perfect.

    Glad to hear that it works.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.