0

I'm trying order some posts by meta_value (featured) and then by title. I'm getting the featured ones in a correct order, however, I got some non-featured mixed after the featured ones, I noticed that this happens only in the first page. Am I doing something wrong? What I need to do to get featured first and non-featured in an alphabeticall order?, this is my query(Using a premium theme called Vantage):

function appthemes_addon_on_top_query( $wp_query ){

    $addon_type = $wp_query->get( 'addon_on_top' );



    if( ! $addon_type || ! appthemes_addon_exists( $addon_type ) ) {
        return;
    }

    $addon_info = appthemes_get_addon_info( $addon_type );


    $flag_key   = $addon_info['flag_key']; // _listing-featured-cat
    $meta_query = (array) $wp_query->get( 'meta_value', 1 );

    $meta_query = array_filter( $meta_query );

    $meta_query[] = array(
        'relation' => 'OR',
        array(
            'key'     => $flag_key,
            'compare' => 'NOT EXISTS',
        ),
        array(
            'relation' => 'OR',
            array(
                'key'   => $flag_key,
                'value' => 1,
            ),
            array(
                'key'     => $flag_key,
                'value'   => 1,
                'compare' => '!=',
            ),
        ),
    );





    $wp_query->set( 'meta_query', $meta_query );
    /* Set an order by meta_value first and then by title */
    $wp_query->set( 'orderby', array( 'meta_value' => 'DESC', 'post_title' => 'ASC' ) );

    /*echo "<pre>"; print_r($meta_query); echo "</pre>";*/
}

featured: http://prntscr.com/kno3lk non-featured: http://prntscr.com/kno3vc

0

The parameter orderby sorts posts by a given parameter. You need the parameter order to set the direction.

More details: Order & Orderby Parameters of WP_Query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.