How to sort a category post by a Custom field?

1

I have a platform in Wordpress where a particular category has a Custom field.

Is it possible to display the posts in this category if they are sorted by the Custom field that I added?

    
asked by anonymous 06.10.2016 / 19:08

1 answer

3

You need to use meta_key as an argument:

$args = array(
    'order'         => 'desc',
    'meta_key'      => 'prod_preco',
    'orderby'       => 'meta_value_num',
    'post_status'   => 'publish',
    'post_type'     => 'produtos',
);
$query = new WP_Query( $args );
...
    
06.10.2016 / 21:14