-1

I am using Elementor Pro and Advanced Queries and also ACF for custom date. I have 2 types of posts that are events - event 1 and event 2. I have an event calendar on the first page showcasing the upcoming event by date (ASC) using custom php and Advanced Querie = works perfectly. BUT as one of the event types are more expensive (better for business) I need it to be shown by dated first. To sum it up I need the events to be showcased like this:

Event 1 (by ASC):

  • August 1
  • August 2
  • Aust 3

Follong in the same post list (by ASC):

Event 2:

  • August 2
  • August 4
  • August 8

I also wantto state that I mostly work with Elementor Pro only and no PHP, I have o experiance in that so I am just searching on internet for codes to help solve my problem.

This is the code I used and that worked to list it by date using ACF and Advanced Querie ID:

add_action( 'elementor/query/my_custom_filter', function( $query ) {
    
  $query->set( 'meta_key', 'datums' );
  $query->set( 'orderby', 'meta_value_num' );
  $query->set( 'order', 'ASC' );

});

Then I found something that would match on internet like this:

add_action( 'elementor/query/my_custom_filter', function( $query ) {
    
  $query->set( 'meta_key', 'datums' );
  $query->set( 'orderby', 'meta_value_num' );
$tax_query = array(
   
    array(
        'taxonomy' => 'category',
        'field' => 'slug',
        'terms' => 'retriti'
    ),
    array(
        'taxonomy' => 'category',
        'field' => 'slug',
        'terms' => 'visas-meditacijas'
    ),
);
    $query->set( 'tax_query', $tax_query );

  $query->set( 'order', 'ASC' );

});

But then the events disapeared at all..

I have find diferen codes online for this as well but thet do not seem to work for my custom filter by date anymore.. Please help me - I am lost and want to cry :D

  • I'm guessing your tax query is now looking for posts that are in _both_ categories, but there appear to be none. You will need to include `'relation' => 'OR',` on the top level, see https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters – CBroe Aug 07 '23 at 06:56
  • And as for how to actually sort posts by category - I guess you'll have to do a bit more research on that, because directly via `order` and `orderby` parameters, that does not appear to be possible, as far as I can tell from the documentation. – CBroe Aug 07 '23 at 07:00
  • Please do not cross-post: choose the site that works best, and only post there. Original: https://wordpress.stackexchange.com/questions/417881/sort-posts-by-category-and-date-using-php-and-custom-query – Caleb Aug 07 '23 at 13:52
  • @Caleb - sorry this is my first time posting. It will not happen again. – Tryingandtrying Aug 07 '23 at 15:13

0 Answers0