admin管理员组

文章数量:1279117

I have this PHP code:

$posts = get_posts([
      'post_type' => 'clen',
      'post_status' => 'publish',
      'numberposts' => -1,
      'orderby' => 'funkcia',
      'order'    => 'DESC'
    ]); 

However, this code does not sort the posts by funkcia field at all.

What is wrong with my code, please?

Thank you

I have this PHP code:

$posts = get_posts([
      'post_type' => 'clen',
      'post_status' => 'publish',
      'numberposts' => -1,
      'orderby' => 'funkcia',
      'order'    => 'DESC'
    ]); 

However, this code does not sort the posts by funkcia field at all.

What is wrong with my code, please?

Thank you

Share Improve this question asked Sep 28, 2021 at 10:09 neisorneisor 1111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

I fixed it with the following code:

$posts = get_posts([
        'post_type'         => 'clen',
        'post_status' => 'publish',
        'numberposts' => -1,
        'meta_key'          => 'funkcia',
        'orderby'           => 'meta_value',
        'order'             => 'ASC'
    ]);

This snippet orders the gotten posts by field funkcia.

本文标签: Order custom post type by custom field (created by PODS) via PHP