Hi @zeus71
Thanks for using PublishPress Future.
It should be possible by clicking the “Expires” heading on the “Post” screen.
Or am I not understanding your question 100% clearly?
Hello @stevejburge
Thanks for your support.
On backend works well, I mean on the frontend.
Regards,
George
Thanks @zeus71
We don’t have any frontend display controls, but we are looking to add this in upcoming releases.
Hello @stevejburge
Is it possible to order posts by expirationdate with any hook on theme functions.php?
Thanks in advance.
Hello, you can do it with a custom loop, this example works for posts and products:
<?php
$args = array(
'post_type' => 'product', // or 'post'
'posts_per_page' => '20',
'post_status' => 'publish',
'return' => 'ids',
'orderby' => 'meta_value',
'meta_key' => '_expiration-date',
'order' => 'ASC', // or 'DESC'
'product_cat' => 'yourcategory' // 'cat' => 'yourcategory'
);
$products = new WP_Query( $args );
if ( $products->have_posts() ) {
while ( $products->have_posts() ) : $products->the_post();
wc_get_template_part( 'content', 'yourcontent' ); // or get_template_part( 'partials/content', 'post' ); for posts
endwhile; // end of the loop.
wp_reset_postdata();
}
?>
You can modify as you like for personalized content.
Greetings 😉
-
This reply was modified 4 years ago by
biboocl.
Hello @biboocl
Thanks for your suggestion, but it didn’t work.
Finally, I made it with the below snippet.
// Short posts by expiry date
function posts_sort_expirationdate( $query ) {
if ( is_admin() || ! $query->is_category('your-category-slug') )
return;
$query->set(
'meta_query', array(
'relation' => 'OR',
array(
'key' => '_expiration-date',
'compare' => 'EXISTS',
),
array(
'key' => '_expiration-date',
'compare' => 'NOT EXISTS',
'value' => '',
),
)
);
$query->set('orderby', 'meta_value_num');
$query->set( 'order', 'ASC' );
return;
}
add_action( 'pre_get_posts', 'posts_sort_expirationdate', 1 );
Regards,
George
Thanks for sharing this @zeus71