solved archvie activities showing wrong order
This commit is contained in:
parent
8afcb066d5
commit
0ee5eadd60
43
archive.php
43
archive.php
|
@ -47,42 +47,23 @@ get_header();
|
|||
the_posts_navigation();
|
||||
//end if is_category faq
|
||||
} elseif (in_category( array( 'activitats') ) ) {
|
||||
//get_template_part( 'template-parts/section', 'each-agenda-entry' );
|
||||
|
||||
$the_query_archive_activitats = new WP_Query(
|
||||
array(
|
||||
//'post_type' => 'post',
|
||||
//'posts_per_page' => '-1', //show all => -1
|
||||
//'tax_query' => array(
|
||||
// array(
|
||||
// 'taxonomy' => 'category',
|
||||
// 'field' => 'slug',
|
||||
// 'terms' => 'activitats'
|
||||
// )
|
||||
//),
|
||||
'meta_query' => array(
|
||||
array( //filter results show only older than today
|
||||
function xxp_order_by_date_end( $query ){
|
||||
if ( ! is_admin() && $query->is_main_query() ){
|
||||
$query->set( 'order_by', 'meta_value' );
|
||||
$query->set( 'order', 'ASC' );
|
||||
$query->set( 'meta_query', array(
|
||||
array(
|
||||
'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
|
||||
'type' => 'DATE',
|
||||
)
|
||||
),
|
||||
'order_by' => 'meta_value', //order by meta value
|
||||
'order' => 'ASC', //order ascendent
|
||||
)
|
||||
);
|
||||
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
|
||||
) );
|
||||
}
|
||||
}
|
||||
add_action( 'pre_get_posts', 'xxp_order_by_date_end');
|
||||
get_template_part( 'template-parts/section', 'each-agenda-entry' );
|
||||
|
||||
//end in_category agenda activitats
|
||||
} elseif (in_category( array( 'convocatories') ) ) {
|
||||
|
|
Loading…
Reference in New Issue