0

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?

1 Answer 1

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).

1
  • Thanks for the input! The big issue with this query is that it sort by artwork title and not by artist name.
    – Systemedic
    Commented Feb 6 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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