0
votes

I need some help. I am trying to create a custom query for my Custom Posts I created in Wordpress, and using Elementor Pro.

On my post, I added a custom field 'sorting' with a numeric value, which I would like to use to order my posts manually.

However, I cannot seem to get this to work.

I am using the latest Elementor pro version.

And I tried following the instructions as per their page: https://developers.elementor.com/custom-query-filter/

Here is my code I added to my theme's functions.php file

// Showing posts ordered by comment count in Posts Widget
add_action( 'elementor/query/speaker_order', function( $query ) {
    // Here we set the query to fetch posts with
    // ordered by comments count
    $query->set( 'orderby', 'sorting' );
} );

I have added 'speaker_order' as the Query ID in the Elementor Editor.

2

2 Answers

1
votes

You are close. There's one thing you left out (if I am grasping what you want to do).

It should look like this:

add_action( 'elementor/query/speaker_order', function( $query ) {
    // Here we set the query to fetch posts with
    // ordered by comments count
    $query->set( 'meta_key', 'sorting' );
    $query->set( 'orderby', 'sorting' );
} );

0
votes

You have to add two more lines of code:

// Showing posts ordered by comment count in Posts Widget
add_action( 'elementor/query/speaker_order', function( $query ) {
    $query->set('meta_key','sorting');
    $query->set('orderby', 'sorting');
    $query->set('orderby','ASC');
  });