How to sort a category post by a Custom field?

Asked

Viewed 285 times

1

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

You can make sure that when you show posts in this category they are sorted by the Custom field I added?

1 answer

3


You need to use meta_key as argument:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.