solved archvie activities showing wrong order

This commit is contained in:
jorge 2024-05-27 10:33:23 +02:00
parent 8afcb066d5
commit 0ee5eadd60
1 changed files with 12 additions and 31 deletions

View File

@ -47,42 +47,23 @@ get_header();
the_posts_navigation(); the_posts_navigation();
//end if is_category faq //end if is_category faq
} elseif (in_category( array( 'activitats') ) ) { } elseif (in_category( array( 'activitats') ) ) {
//get_template_part( 'template-parts/section', 'each-agenda-entry' );
$the_query_archive_activitats = new WP_Query( function xxp_order_by_date_end( $query ){
array( if ( ! is_admin() && $query->is_main_query() ){
//'post_type' => 'post', $query->set( 'order_by', 'meta_value' );
//'posts_per_page' => '-1', //show all => -1 $query->set( 'order', 'ASC' );
//'tax_query' => array( $query->set( 'meta_query', array(
// array( array(
// 'taxonomy' => 'category',
// 'field' => 'slug',
// 'terms' => 'activitats'
// )
//),
'meta_query' => array(
array( //filter results show only older than today
'key' => 'xxp_agenda_date_end', 'key' => 'xxp_agenda_date_end',
'value' => date("Y-m-d"), // consider using date_i18n() https://developer.wordpress.org/reference/functions/date_i18n/ 'value' => date("Y-m-d"),
'compare' => '>', //show events before today 'compare' => '>', //show events before today
'type' => 'DATE', 'type' => 'DATE',
) )
), ) );
'order_by' => 'meta_value', //order by meta value }
'order' => 'ASC', //order ascendent }
) add_action( 'pre_get_posts', 'xxp_order_by_date_end');
); get_template_part( 'template-parts/section', 'each-agenda-entry' );
if ( $the_query_archive_activitats->have_posts() ) :
while ( $the_query_archive_activitats->have_posts() ) : $the_query_archive_activitats->the_post();
get_template_part( 'template-parts/section', 'each-agenda-entry' );
endwhile;//end of the loop
// pagination will not work for custom_query, why and fix: https://wordpress.stackexchange.com/a/120408
// the_posts_navigation();
endif; //end if the_query_archive_activitats
wp_reset_postdata(); //reset custom query
//end in_category agenda activitats //end in_category agenda activitats
} elseif (in_category( array( 'convocatories') ) ) { } elseif (in_category( array( 'convocatories') ) ) {