solved archvie activities showing wrong order
This commit is contained in:
parent
8afcb066d5
commit
0ee5eadd60
39
archive.php
39
archive.php
|
@ -47,43 +47,24 @@ 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 ){
|
||||||
|
if ( ! is_admin() && $query->is_main_query() ){
|
||||||
|
$query->set( 'order_by', 'meta_value' );
|
||||||
|
$query->set( 'order', 'ASC' );
|
||||||
|
$query->set( 'meta_query', array(
|
||||||
array(
|
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
|
|
||||||
'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');
|
||||||
);
|
|
||||||
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' );
|
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') ) ) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue