Tagged: enfold, post order
Hi there,
I have two pages with posts, filtered by category.
First page: posts with category 2014
Second page: posts with category 2015
The post get ordered by date, with the newest at the top.
I would like to show one post on both pages: in 2014 as an announcement, in 2015 as a reminder.
As this post was the last in 2014 it should get to the top. This also works.
But in 2015 this post should be the last while oldest – but it also gets displayes first.
How can I solve this?
Best regards
Marko
Hey mkuzman,
Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?
Best regards,
Victoria
Hi,
Thank you for the info. What is the login url? The default “wp-admin” or “wplogin” is not working. Please try to use the “pre_get_posts” filter. Example.
function ava_conditional_pre_get_posts_order( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( is_page(3827) ) {
$query->set( 'orderby', 'date' );
$query->set( 'order', 'ASC' );
}
if ( is_page(3824) ) {
$query->set( 'orderby', 'date' );
$query->set( 'order', 'DESC' );
}
return;
}
add_action( 'pre_get_posts', 'ava_conditional_pre_get_posts_order', 1 );
Adjust the value as necessary.
// https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
Best regards,
Ismael
Hi,
Thank you for the update. We added the filter in the functions.php file.
Best regards,
Ismael
Hi Ismael,
thank you – now it seems to work.
Best regards
Marko