admin管理员组

文章数量:1125919

I have a website that lists paintings. All these paintings are made by various artists. I've added a custom post type "paintings" and created a form so each painting can be easily entered. What I want is a way to sort these paintings by artist. I can't figure out the correct way to do this.

What I have done now is created the following query;

add_action( 'elementor/query/kunst_op_kunstenaar', function( $query ) {
    
  $query->set( 'meta_key', 'kunstenaar_tekst');
  $query->set( 'orderby', array(
      'meta_value_num' => 'ASC',
      'date' => 'ASC'
  ));

And that works, sort of, when adding a new artist this will get a new ID of course and will sort them on the last page, since the ID is the highest.

How can I create a query that will sort the artists the right way?

I have a website that lists paintings. All these paintings are made by various artists. I've added a custom post type "paintings" and created a form so each painting can be easily entered. What I want is a way to sort these paintings by artist. I can't figure out the correct way to do this.

What I have done now is created the following query;

add_action( 'elementor/query/kunst_op_kunstenaar', function( $query ) {
    
  $query->set( 'meta_key', 'kunstenaar_tekst');
  $query->set( 'orderby', array(
      'meta_value_num' => 'ASC',
      'date' => 'ASC'
  ));

And that works, sort of, when adding a new artist this will get a new ID of course and will sort them on the last page, since the ID is the highest.

How can I create a query that will sort the artists the right way?

Share Improve this question asked Feb 6, 2024 at 16:25 SystemedicSystemedic 1
Add a comment  | 

1 Answer 1

Reset to default 0

I don't know much about elementor, but to keep this as a Purely WordPress answer you need to change your query to sort by post name. The code you provided looks like a pre-query filter so you should try this:

add_action( 'elementor/query/kunst_op_kunstenaar', function( $query ) {
    
  $query->set( 'order', 'ASC');
  $query->set( 'orderby', 'title');
}

This sets your order by function to sort by title and then order to ascending (a-z).

本文标签: queryElementorSort by name